[issue1565] round(x,y) doesn't behave as expected, round error

Amaury Forgeot d'Arc report at bugs.python.org
Fri Dec 7 11:13:48 CET 2007


Amaury Forgeot d'Arc added the comment:

Your function is not better:

>>> print my_round(s,2)
1.41
>>> my_round(s,2)
1.4099999999999999

print uses str(), and restricts itself to 12 significant digits.
the direct call uses repr(), and display the most precise number.

The problem is not in the computation, but is inherent to the 'float'
type which cannot represent 1.41 exactly. Please carefully read the faq
entry above.

__________________________________
Tracker <report at bugs.python.org>
<http://bugs.python.org/issue1565>
__________________________________


More information about the Python-bugs-list mailing list