Python float representation error?

nikie n.estner at gmx.de
Sun Mar 26 19:18:05 EST 2006


> try running this in python:
>
> print [39.95]
>
> the output i get is:
> [39.950000000000003]
>
> what's up with that?

That's perfectly normal - some numbers aren't exactly expressible as
binary floating points, just like 1/3 isn't expressible as a decimal
floating point number.

Here's a good link on floating point arithmetic:
http://docs.sun.com/source/806-3568/ncg_goldberg.html




More information about the Python-list mailing list