floating point math results question

Doug Farrell writeson at earthlink.net
Fri Jan 25 16:48:32 CET 2002


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
>>> 4/5.0
>>> 4.0/5

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,

More information about the Python-list mailing list