round() function strange behaviour

brobbins333 at shaw.ca brobbins333 at shaw.ca
Sun Mar 10 10:52:17 EST 2002


OK, that makes perfect sense. In my case, I was simply looking for a
predictable way to return a number with two decimal places -- knowing
that it will be an approximation of Python's approximation. Obviously,
using round() is not the way to go about this. I'll figure it out.
Thanks for all the very informative responses.

Bruce

On 10 Mar 2002 12:12:10 GMT, scarblac at pino.selwerd.nl (Remco Gerlich)
wrote:

>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