Where is the correct round() method?
Terry Reedy
tjreedy at udel.edu
Sun Jul 27 21:32:06 EDT 2008
Gary Herron wrote:
> josh logan wrote:
>> I need a round function that _always_ rounds to the higher integer if
>> the argument is equidistant between two integers. In Python 3.0, this
>> is not the advertised behavior of the built-in function round() as
>> seen below:
>>>>> round(2.5)
>>>>>
>> 2
> Huh?
> >>> round(2.5)
> 3.0
As the OP said, PY 3.0, where statisticians' unbiased round to even was
explicitly adopted. (I think before it was maybe left to the C library?)
>> I would think this is a common need,
If you need any particular rounding for legal/finance-rule reasons, you
probably need the decimal module, which has several rounding modes and
other features catering to money calculation rules.
For general data analysis with floats, round to even is better.
tjr
More information about the Python-list
mailing list