[issue24827] round(1.65, 1) return 1.6 with decimal

Huan Wang report at bugs.python.org
Sun Jul 30 07:45:01 EDT 2017


Huan Wang added the comment:

Hi Mark,

Thank you for your reply.

I went over again the answer from Zachary Ware published on 2015-08-08 09:36. I got the point that it is better to use string type of number.

>>> from decimal import Decimal, ROUND_HALF_UP
>>> Decimal("1.45")
Decimal('1.45')

>>> Decimal(Decimal("1.45").quantize(Decimal("0.1"), rounding=ROUND_HALF_UP))
Decimal('1.5')

I think it is better to make a tip in the Python tutorial.

----------

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


More information about the Python-bugs-list mailing list