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 mark.dickinson, steve21
Date 2009-06-07.14:00:30
SpamBayes Score 2.6312286e-14
Marked as misclassified No
Message-id <1244383233.62.0.577564422685.issue6228@psf.upfronthosting.co.za>
In-reply-to
Content
Thanks for the report.

This is fixed in Python 3.1 (except on a few unusual hardware/OS 
combinations):

Python 3.1rc1+ (py3k:73252, Jun  6 2009, 10:35:36) 
[GCC 4.0.1 (Apple Computer, Inc. build 5367)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> round(697.04157958254996, 10)
697.0415795825

It's a "won't fix" for Python 2.x.  Rounding to 10 decimal places 
involves multiplying by 10**10., rounding to the nearest integer, then 
dividing by 10**10. again;  the problem in this case is that 
multiplication by 10.**10 is inexact, and the error involved in the 
multiplication by 10**10. pushes the value from the 'round down' region 
into the 'round up region':

Python 2.7a0 (trunk:73252, Jun  6 2009, 10:16:08) 
[GCC 4.0.1 (Apple Computer, Inc. build 5367)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> 697.04157958254996 * 10**10
6970415795825.5
[38623 refs]

There's no easy way to fix this, short of using multiple-precision 
arithmetic to do the rounding (which is what Python 3.1 does).


By the way, Python's float can't represent the number

697.04157958254996

exactly (assuming IEEE 754 arithmetic):  the closest it gets is the 
value:

697.041579582549957194714806973934173583984375

but the repr of a float (in Python 3.0 and 2.x) only produces 17 
significant digits, since that's enough to guarantee that the
repr() value evaluates back to the correct float (assuming correct
rounding).
History
Date User Action Args
2009-06-07 14:00:33mark.dickinsonsetrecipients: + mark.dickinson, steve21
2009-06-07 14:00:33mark.dickinsonsetmessageid: <1244383233.62.0.577564422685.issue6228@psf.upfronthosting.co.za>
2009-06-07 14:00:32mark.dickinsonlinkissue6228 messages
2009-06-07 14:00:31mark.dickinsoncreate