round(22.47,2) gives 22.469999999999999?
thomaso at best.com
Wed Aug 6 13:38:09 CEST 2003
Eric van Riet Paap wrote:
> On python2.1.3, python2.2.1 and python2.2.3 round(22.47,2) gives
> 22.469999999999999 . Does anyone know if this is a bug or some weird, yet
> unexpected, behaviour?
> P.S. I haven't tested python2.3, but python1.5.2 doesn't have this problem.
In IDLE, just typing:
That seems to indicate that 22.47 is best approximated by the floating
Rounding should probably not be used for gettting "formatable" values.
Instead, you can do something like:
>>> "%.2f" % 22.47
if you want a string version of the number rounded to 2 decimal places.
More information about the Python-list