benjamin.kaplan at case.edu
Fri Aug 13 03:19:40 CEST 2010
On Thu, Aug 12, 2010 at 6:14 PM, Ned Deily <nad at acm.org> wrote:
> In article <i41p6e$1fg$1 at dough.gmane.org>,
> Christian Heimes <lists at cheimes.de> wrote:
>>> Is there a way I can keep my floating point number as I typed it? For
>>> example, I want 34.52 to be 34.52 and NOT 34.5200000002.
>> This isn't a Python issue. Python uses IEEE 754  double precision
>> floats like most other languages. 34.52 can't be stored in a float. The
>> next valid float is 34.5200000002.
> 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))'
> $ python2.7 -c 'print(repr(34.52))'
> $ python3.1 -c 'print(repr(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
>>> >>> _ * 10**10
> Ned Deily,
> nad at acm.org
More information about the Python-list