Where is the correct round() method?

Gary Herron gherron at islandtraining.com
Mon Jul 28 00:34:24 EDT 2008


josh logan wrote:
> On Jul 27, 8:45 pm, pigmartian <scottp... at comcast.net> wrote:
>   
>> it could be that 3.0 is using "banker's rounding" --- rounding to the
>> even digit.  the idea behind it behind it being to reduce error
>> accumulation when working with large sets of values.
>>
>>     
>>> Works for me on Python 2.5 on Linux running on "Intel(R) Core(TM)2 Duo
>>> CPU".  What system are you on?
>>>       
>>> It could be that 2.5 is really 2.49999... which would round down to 2,
>>> but on any modern CPU (using IEEE floating point), 2.5 should be
>>> representable exactly.
>>>       
>>     
>
> That's exactly what's happening, pigmartian. Thank you for explaining
> the reasoning behind this change.
> So am I relegated to building my own round() function that behaves
> like the original function? Or did they move the functionality to a
> new method somewhere for backwards-compatibility?
>   

This will work as you wish:
  math.floor(x+0.5)

Gary Herron


> --
> http://mail.python.org/mailman/listinfo/python-list
>   




More information about the Python-list mailing list