[Tutor] Is something wrong with my round() function?
hcohen2
hcohen2 at comcast.net
Tue Jan 20 11:35:16 EST 2004
The obvious answer is 'YES', but what's causing this strange behaviour?
>>> ans = 48.936
>>> round(ans, 1)
48.899999999999999
>>> round(ans, 2)
48.939999999999998
>>> round(ans, 3)
48.936
>>> round(ans, 4)
48.936
>>> round(ans, 2)
48.939999999999998
>>> round(ans, 1)
48.899999999999999
>
I have another example were I was using a class to compute the total
room rates that were supposed to be rounded to the nearest cent and they
looked like the above sample, however, using the round(<week rate>, 1)
gave it properly to the nearest dime.
Using python ver 2.2.2 on Linux (Mandrake 9.1) on an IBM laptop.
TIA
More information about the Tutor
mailing list