classification
Title: round Decimal edge case
Type: Stage: resolved
Components: Library (Lib) Versions: Python 2.7
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: ahrvoje, benjamin.peterson
Priority: normal Keywords:

Created on 2020-01-14 21:08 by ahrvoje, last changed 2020-01-15 03:12 by benjamin.peterson. This issue is now closed.

Messages (2)
msg359999 - (view) Author: Hrvoje Abraham (ahrvoje) Date: 2020-01-14 21:08
>>> from decimal import Decimal
>>> round(Decimal('-123.499999999999999999999999999999999999999999'))
-124.0

I would expect -123.0, even considering Py2 rounding convention details (away from zero), Decimal rounding convention (default rounding=ROUND_HALF_EVEN), floating point specifics...

Works as expected in Py3. Both Py2 and Py3 use same default Decimal rounding=ROUND_HALF_EVEN.

Could be I'm missing some detail...
msg360021 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2020-01-15 03:12
On Python 2, round just converts the decimal to a float. So, this is a consequence of:

>>> float(Decimal('-123.499999999999999999999999999999999999999999'))
-123.5
History
Date User Action Args
2020-01-15 03:12:42benjamin.petersonsetstatus: open -> closed

nosy: + benjamin.peterson
messages: + msg360021

resolution: not a bug
stage: resolved
2020-01-14 21:08:15ahrvojecreate