This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author mark.dickinson
Recipients falk_steinhauer, mark.dickinson
Date 2007-12-31.19:15:16
SpamBayes Score 0.05271116
Marked as misclassified No
Message-id <1199128517.18.0.407345328139.issue1694@psf.upfronthosting.co.za>
In-reply-to
Content
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
History
Date User Action Args
2007-12-31 19:15:17mark.dickinsonsetspambayes_score: 0.0527112 -> 0.05271116
recipients: + mark.dickinson, falk_steinhauer
2007-12-31 19:15:17mark.dickinsonsetspambayes_score: 0.0527112 -> 0.0527112
messageid: <1199128517.18.0.407345328139.issue1694@psf.upfronthosting.co.za>
2007-12-31 19:15:17mark.dickinsonlinkissue1694 messages
2007-12-31 19:15:16mark.dickinsoncreate