Zachary Ware added the comment:

The rounding mode of the default context is ROUND_HALF_EVEN[1]:

>>> import decimal
>>> decimal.getcontext()
Context(prec=28, rounding=ROUND_HALF_EVEN, Emin=-999999, Emax=999999, 
capitals=1, clamp=0, flags=[], traps=[InvalidOperation, DivisionByZero, 
Overflow])

For your examples near the end, see [2]:

>>> round(2.675, 2)
2.67
>>> round(decimal.Decimal('2.675'), 2)
Decimal('2.68')
>>> decimal.Decimal(2.675)
Decimal('2.67499999999999982236431605997495353221893310546875')
>>> round(_, 2)
Decimal('2.67')

[1] https://docs.python.org/3/library/decimal.html#decimal.ROUND_HALF_EVEN
[2] https://docs.python.org/3/tutorial/floatingpoint.html

----------
nosy: +zach.ware
resolution:  -> not a bug
stage:  -> resolved
status: open -> closed

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

Reply via email to