[issue16460] Strange results for floor division ("//") with non-integer divisors

Stefan Krah report at bugs.python.org
Mon Nov 12 15:25:12 CET 2012


Stefan Krah added the comment:

Any programming language that uses binary floats behaves like that
and it is actually what people expect.

If you want behavior that is closer to pencil and paper calculations,
you need to use decimal:

>>> Decimal(1) // Decimal("0.1")
Decimal('10')


Contrast with:

>>> Decimal(1) // Decimal(0.1)
Decimal('9')


The reason:
>>> Decimal("0.1")
Decimal('0.1')


>>> Decimal(0.1)
Decimal('0.1000000000000000055511151231257827021181583404541015625')

----------

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


More information about the Python-bugs-list mailing list