round() wrong in Python 2.4?
Jeremy Sanders
jeremy+complangpython at jeremysanders.net
Tue Sep 13 09:25:39 EDT 2005
Nils Grimsmo wrote:
> Why did round() change in Python 2.4?
It the usual floating point representation problem. 0.0225 cannot be
represented exactly:
xpc20:~> python
Python 2.3.4 (#1, Mar 14 2005, 16:47:22)
[GCC 3.4.3 20041212 (Red Hat 3.4.3-9.EL4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> 0.0225
0.022499999999999999
See
http://www.python.org/doc/current/tut/node13.html#SECTION0013800000000000000000
If you need exact maths, then you're better off using integers or decimal
arithmetic.
Jeremy
--
Jeremy Sanders
http://www.jeremysanders.net/
More information about the Python-list
mailing list