[issue21179] Rounding half to even

Josh Rosenberg report at bugs.python.org
Wed Apr 9 03:50:03 CEST 2014


Josh Rosenberg added the comment:

Python 3.2-3.4 (probably all of 3.x) use round half even, but testing 2.7.3 on Ubuntu confirms what you say. In terms of the decimal constants, Py2.7 round() appears to use decimal.ROUND_HALF_UP behavior while 3.x uses decimal.ROUND_HALF_EVEN behavior.

Looks like someone accidentally copied Py3 docs down to Py2; according to https://docs.python.org/3/whatsnew/3.0.html :

>The round() function rounding strategy and return type have changed. Exact halfway cases are now rounded to the nearest even result instead of away from zero. (For example, round(2.5) now returns 2 rather than 3.) round(x[, n]) now delegates to x.__round__([n]) instead of always returning a float. It generally returns an integer when called with a single argument and a value of the same type as x when called with two arguments.

Looks like the behaviors never changed, but the docs for round in Py2 are incorrect.

----------
nosy: +josh.rosenberg

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue21179>
_______________________________________


More information about the Python-bugs-list mailing list