a print bug?

Summercoolness at gmail.com Summercoolness at gmail.com
Fri Jul 28 00:22:46 EDT 2006


Duncan Booth wrote:
> 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.

This is the expected behavior though... even school when they first
teach "rounding off", they will tell you 1.23445 rounding off to 3
decimal places is not 1.235.... and i don't see anything weird about
the two lines above.




More information about the Python-list mailing list