Mark Dickinson added the comment:

Huan,

This isn't a bug: see the earlier comments from Zachary Ware on this issue for 
explanations. When you compute `rounded(1.45, 0.1)`, you convert the *float* 
1.45 to a Decimal instance. Thanks to the What You See Is Not What You Get 
nature of binary floating point, the actual value stored for 1.45 is:

1.4499999999999999555910790149937383830547332763671875

Conversion from float to Decimal is exact, so the Decimal value you're working 
with is also a touch under 1.45:

>>> from decimal import Decimal
>>> Decimal(1.45)
Decimal('1.4499999999999999555910790149937383830547332763671875')

And so it correctly rounds down to `1.4`.

----------
nosy: +mark.dickinson

_______________________________________
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