This math scares me

Fredrik Lundh fredrik at pythonware.com
Mon Mar 12 16:57:19 EST 2001


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

see

http://www.python.org/cgi-bin/moinmoin/FrequentlyAskedQuestions

    Q. Floating point is broken!

    A. Binary floating point cannot represent decimal
    fractions exactly, so some rounding always occurs

and

http://www.python.org/cgi-bin/moinmoin/RepresentationError

    ... some (most, actually) decimal fractions cannot
    be represented exactly as binary (base 2) fractions.
    This is the chief reason why Python (or Perl, C, C++,
    Java, Fortran, ...) often won't display the exact
    decimal number you expect ...

Cheers /F

<!-- pythonworks 1.2 coming soon:
http://www.pythonware.com/products/works/index.htm
-->





More information about the Python-list mailing list