This math scares me

Grant Edwards grante at visi.com
Mon Mar 12 16:50:31 EST 2001


In article <3aad4062.1290021 at News.CIS.DFN.DE>, costas at springmail.com wrote:

>Ok, I can see maybe division having problems. But why does addition of
>the two numbers below:
>
>5.01+5.54
>
>give me this?
>
>10.550000000000001

Sorry. That's how floating point numbers on computers work.

Many numbers (including 10.01) can't be represented exactly
in the binary representation used by your computer.

Therefore floating-point results are never going to be exact.  

>I hope its some setting that can take care of this. I am using Python
>under Windows 98.

Use integer or fixed-point BCD math if you need exact results.

-- 
Grant Edwards                   grante             Yow!  MMM-MM!! So THIS is
                                  at               BIO-NEBULATION!
                               visi.com            



More information about the Python-list mailing list