round() function strange behaviour

Remco Gerlich scarblac at pino.selwerd.nl
Sun Mar 10 07:12:10 EST 2002


brobbins333 at shaw.ca <brobbins333 at shaw.ca> wrote in comp.lang.python:
> I understand the problem of rounding errors with binary numbers.
> However, the rounding functions of other languages  work around it and
> return a usable result. What have they got that Python hasn't got?

The other programs are liars - they show a rounded result, the way Python's
print does.

It is not possible to represent 56.79 in a finite binary float - it's a
repetitive fraction in binary.

Python decided not to hide this in the interactive interpreter. If you print
out a number, it looks the way it does in other languages. Under the hood,
they all do the same thing.

-- 
Remco Gerlich



More information about the Python-list mailing list