floating point math results question

Doug Farrell writeson at earthlink.net
Fri Jan 25 10:48:32 EST 2002


Hi,

I'm promoting the use of Python where I work and was asked a question
by one of the guys who is trying it out. He showed me some math that
gave what we both thought were unusual results. Here's what we did:

>>> 4.0/5.0
0.80000000000000004
>>> 4/5.0
0.80000000000000004
>>> 4.0/5
0.80000000000000004


The results should be 0.8 and that's it. Where is the 00000000000004
coming from? Is this just an artifact of the use of binary
representation of floating point numbers or some artifact of printing
a floating point number?

Thanks in advance,
Doug



More information about the Python-list mailing list