This math scares me

costas at springmail.com costas at springmail.com
Mon Mar 12 17:07:30 EST 2001


On Mon, 12 Mar 2001 21:50:31 GMT, grante at visi.com (Grant Edwards)
wrote:

>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.

I will also tell my customers that this is the new math. Maybe I will
tell them to use a slide ruler too .

Joking aside, this should be fixed to display the number correctly. If
I use 'print 5.01+5.54" then it gives the result correctly. It seems
to happen only if you type it in the command line without a print
command.

Costas





More information about the Python-list mailing list