[Tutor] Python 2.5.4 - error in rounding

Neven Goršić neven.gorsic at gmail.com
Fri May 21 12:17:59 CEST 2010


Hi!

I run into Python error in rounding and not know how to predict when it will
occur in order to prevent wrong result.
What can I do to assure accurate result?

>>> "%.2f" % 0.445
'0.45'                                   correct
>>> "%.2f" % 0.455
'0.46'                                   correct
>>> "%.2f" % 0.465
'0.47'                                   correct
>>> "%.2f" % 0.475
'0.47'                                   not correct
>>> "%.2f" % 0.485
'0.48'                                   not correct
>>> "%.2f" % 0.495
'0.50'                                   correct

Neven
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20100521/059c5fd1/attachment.html>


More information about the Tutor mailing list