Floating numbers

Nobody nobody at nowhere.com
Fri Aug 13 01:34:52 EDT 2010


On Thu, 12 Aug 2010 18:19:40 -0700, Benjamin Kaplan wrote:

> But that's not keeping the number the way it was typed. It's just not
> showing you the exact approximation.

Nor is 34.520000000000003 showing you the "exact approximation".

The closest "double" to 34.52 is 4858258098025923 / 2**47, whose exact
decimal representation is:

	34.52000000000000312638803734444081783294677734375

The decimal representation of 1/(2**n) for n>0 always ends in 5. As a
consequence of this, the exact decimal representation of any binary
floating-point value which isn't itself an integer must end in 5.




More information about the Python-list mailing list