New submission from priska:

The behavior of the round() function has changed between Python 2.x and 
Python3.x. 

>From the release notes of Python 3.0: "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."

2to3 conversion does not take this into account and thereby changes code 
behavior.

Suggested translations:

round(n) -> float(math.floor(n + math.copysign(0.5, n)))

or 

round(n) -> float(math.trunc(n + math.copysign(0.5, n)))

----------
components: 2to3 (2.x to 3.x conversion tool)
messages: 244951
nosy: priska
priority: normal
severity: normal
status: open
title: Missing fixer for changed round() behavior
type: behavior

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue24403>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to