a print bug?

Summercoolness at gmail.com Summercoolness at gmail.com
Fri Jul 28 02:21:22 EDT 2006


Steve Holden wrote:
> You obviously haven't yet passed your floating-point number proficiency
> test yet. Please restrict yourself to integers until you understand the
> difficulties that inaccuracies in floating-point can create ;-)

hm, actually, i understand the limitation of floating point.
but my real concern is, how come "print" favors one version over the
other...
the first version will favor the correct rounding, while the second
doesn't favor it.  to me, this is biased computing....  i will feel
happier if the behavior is consistent.  (such as the first line
printing out as 1.2344999999999) .  if most people favor the behavior
of line 1, that is, silently rounding off to about the 11th decimal
places, then why doesn't printing with formatting also use that same
behavior, which is rounding off to the 11th places first, and then
round off to whatever the user wants.

>>>>print 1.2345

> 1.2345

>>>>print "%10.3f" % 1.2345

>      1.234

but then again, i just realize even if i do a

>>> round(1.2344999999999999999, 6)

1.2344999999999999

so even if you round it off, it is still represented the same way....
still, how "print" handles 1.2345 and treating it and printing it as
1.2345, i wonder why we don't make the "print with formatting" the same
behavior, treating it as 1.2345 first and round it off to 1.235




More information about the Python-list mailing list