Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

round Decimal edge case #83516

Closed
ahrvoje mannequin opened this issue Jan 14, 2020 · 2 comments
Closed

round Decimal edge case #83516

ahrvoje mannequin opened this issue Jan 14, 2020 · 2 comments
Labels
stdlib Python modules in the Lib dir

Comments

@ahrvoje
Copy link
Mannequin

ahrvoje mannequin commented Jan 14, 2020

BPO 39335
Nosy @benjaminp

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = <Date 2020-01-15.03:12:42.516>
created_at = <Date 2020-01-14.21:08:15.098>
labels = ['invalid', 'library']
title = 'round Decimal edge case'
updated_at = <Date 2020-01-15.03:12:42.510>
user = 'https://bugs.python.org/ahrvoje'

bugs.python.org fields:

activity = <Date 2020-01-15.03:12:42.510>
actor = 'benjamin.peterson'
assignee = 'none'
closed = True
closed_date = <Date 2020-01-15.03:12:42.516>
closer = 'benjamin.peterson'
components = ['Library (Lib)']
creation = <Date 2020-01-14.21:08:15.098>
creator = 'ahrvoje'
dependencies = []
files = []
hgrepos = []
issue_num = 39335
keywords = []
message_count = 2.0
messages = ['359999', '360021']
nosy_count = 2.0
nosy_names = ['benjamin.peterson', 'ahrvoje']
pr_nums = []
priority = 'normal'
resolution = 'not a bug'
stage = 'resolved'
status = 'closed'
superseder = None
type = None
url = 'https://bugs.python.org/issue39335'
versions = ['Python 2.7']

@ahrvoje
Copy link
Mannequin Author

ahrvoje mannequin commented Jan 14, 2020

>>> 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...

@ahrvoje ahrvoje mannequin added stdlib Python modules in the Lib dir labels Jan 14, 2020
@benjaminp
Copy link
Contributor

On Python 2, round just converts the decimal to a float. So, this is a consequence of:

>>> float(Decimal('-123.499999999999999999999999999999999999999999'))
-123.5

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stdlib Python modules in the Lib dir
Projects
None yet
Development

No branches or pull requests

1 participant