[issue1694] floating point number round failures under Linux

Mark Dickinson report at bugs.python.org
Mon Dec 31 20:15:17 CET 2007


Mark Dickinson added the comment:

Is there anything in the Python documentation that implies that '%.1f' % 2.25 should be the string '2.3'?  I know 
that the documentation for the builtin round function implies that round(2.25, 1) should be (the closest 
representable float to) 2.3, but that's a separate issue.

As far as I can tell, the float formatting of Python derives its behaviour fairly directly from that of the C 
library.  And the C language specification seems to be pretty much silent on the exact rounding behaviour of the 
%e, %f and %g conversion specifiers, so it's not clear that either the Linux result or the Windows result is wrong.  
I'm actually more surprised by the Windows result:  I'd expect %f to do round-to-nearest, with halfway results like 
this one rounded to the string with even last digit.

Incidentally, on OS X 10.4.11/Intel, I get the same as on Linux:

Python 2.5.1 (r251:54863, Dec 18 2007, 11:48:56) 
[GCC 4.0.1 (Apple Computer, Inc. build 5370)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> print '%.1f' % 2.25
2.2

----------
nosy: +marketdickinson

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


More information about the Python-bugs-list mailing list