Floating numbers

Ned Deily nad at acm.org
Fri Aug 13 04:10:38 CEST 2010


In article 
<AANLkTi=kOm3XBkNmMvwbHxxSvnYA_kUCOKBNpZQp2JM8 at mail.gmail.com>,
 Benjamin Kaplan <benjamin.kaplan at case.edu> wrote:
> > Well, it is a *bit* of a Python issue since, as others have pointed out,
> > Python's behavior has changed due to the implementation of Gay's
> > rounding algorithm in 3.1 and also in 2.7:
> >
> > $ python2.6 -c 'print(repr(34.52))'
> > 34.520000000000003
> > $ python2.7 -c 'print(repr(34.52))'
> > 34.52
> > $ python3.1 -c 'print(repr(34.52))'
> > 34.52
> But that's not keeping the number the way it was typed. It's just not
> showing you the exact approximation. It doesn't get rid of rounding
> errors.
> >>> 34.52
> 34.52
> >>> >>> _ * 10**10
> 345200000000.00006

Yes, as discussed earlier in this thread and I didn't mean to imply 
otherwise.   I should have worded my comment differently: the main 
reason for making it was to point out that the new float repr format 
feature is also in 2.7.

-- 
 Ned Deily,
 nad at acm.org




More information about the Python-list mailing list