round() wrong in Python 2.4?

Antoon Pardon apardon at forel.vub.ac.be
Wed Sep 14 06:58:44 EDT 2005


Op 2005-09-13, Robert Kern schreef <rkern at ucsd.edu>:
> Jeremy Sanders wrote:
>> Nils Grimsmo wrote:
>> 
>>>Why did round() change in Python 2.4?
>> 
>> It the usual floating point representation problem. 0.0225 cannot be
>> represented exactly:
>
> That's not what he's asking about. He's asking why his Python 2.3 rounds
> 0.0225 *up* to 0.023 while his Python 2.4 rounds *down* to 0.022. It's
> the change in behavior that he's concerned with and isn't just the usual
> floating point problem.

I would say the usual floating point problem is involved.

Python 2.3 isn't rounding 0.0225 up while pyton 2.4 rounds it down.

0.0225 isn't representable and it happens that the actual number
you get differ. Now which number python should choose when it is
fed 0.0225, I don't know. But expressing the different behaviour
as a change in round, suggest that the O.P. would be wise to
learn about floating point problems

-- 
Antoon Pardon



More information about the Python-list mailing list