[Tutor] The '45' bug in round()
andrew clarke
mail at ozzmosis.com
Mon Mar 19 11:28:33 CET 2007
On Mon, Mar 19, 2007 at 03:04:03AM -0700, Dick Moores wrote:
> Yesterday I was shocked, SHOCKED, to discover that round() is
> occasionally rounding incorrectly. For example,
"Garbage In, Garbage Out" :-)
Floating point numbers in Python (and other computer languages) are only
an approximation:
>>> print round(0.145, 2)
0.14
>>> 0.145
0.14499999999999999
>>> print round(0.1450000001, 2)
0.15
http://docs.python.org/tut/node16.html has some more information about
this.
More information about the Tutor
mailing list