[Python-Dev] builtin round 2.7

Kristján Valur Jónsson kristjan at ccpgames.com
Sat Aug 7 11:59:21 CEST 2010


Hi there.
I just hit a problem in my company, in the process of upgrading from stackless 2.5 to 2.7.
Some rounding code, that was (foolishly) using "%.*f" string formatting to achieve floating point rounding started providing different results from before.  I explained this away to QA and Developement as a) you shouldn't do that, and b) string representation of floats became better and "more correct" in 2.7.  For UI rounding, I directed them to the Decimal module.

So far so good.

But it appears that the builtin round() method also changed.  Whereas I see the changing of floating point representation in string formatting as not being very serious, why did the arithmetic function round() have to change?  I don't see this mentioned in the release notes and was initially a bit puzzled by it.  Hasn't anyone else been hit by the discrepancy?

(and, yes, I know it is now more correct, as seen by round(5.55, 1)  (5.6 in py2.5, 5.5 in py 2.7 which is correct since 5.55 is actually 5.549999... )

Perhaps the release notes need updating?

K


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20100807/9623e6f8/attachment.html>


More information about the Python-Dev mailing list