a print bug?
Duncan Booth
duncan.booth at invalid.invalid
Thu Jul 27 04:16:20 EDT 2006
Summercoolness at gmail.com wrote:
>
> Sybren Stuvel wrote:
>> It has nothing to do with the print command, and everything with
>> floating point precision. See http://docs.python.org/tut/node16.html
>
>
> how about the discrepancy between
>
>>>> print 1.2345
>
> 1.2345
>
>>>> print "%10.3f" % 1.2345 # seems like a bug
>
> 1.234
>
> the first one, print knows enough to recognize and print it as 1.2345.
> however, in the second line, when it is round off, it doesn't know it
> is 1.2345 any more.
>
But you wouldn't complain about this would you?
>>> print "%10.4f" % 1.23445
1.2345
>>> print "%10.3f" % 1.23445
1.234
A value which is slightly than 1.2345 prints to 4 decimal places as 1.2345
and to 3 decimal places as 1.234.
That's all that happens with your value as well: 1.2345 is not exactly
representable as a floating point number, and the nearest representable
number is less than 1.2345.
More information about the Python-list
mailing list