Rounding curiosity

PyBo bartley9 at pacbell.net
Tue Nov 16 21:22:55 EST 2004


What's wrong with this picture?

>>> x = 500000000.0
>>> y = x / (1024 * 1024)
>>> y
476.837158203125
>>> z = round(y, 2)
>>> z
476.83999999999997

I have tried this and get the same result using different CPU's and operating systems.
Obviously, '476.83999999999997' is not rounded to two decimal places.

Or am I doing something wrong?



More information about the Python-list mailing list