The error below occurs on the 14th decimal:
>>> 1001*.2
200.20000000000002
Here* the error occurs on the 18th decimal digit:
>>> from decimal import Decimal
>>> Decimal.from_float(.1)
Decimal('0.1000000000000000055511151231257827021181583404541015625')
# ^
# |_ here
*Note: I used Fraction
since >>> 0.1
is displayed as 0.1
in the console, but I think this is related to how it's printed, not how it's stored.
Questions:
- Is there a way to determine on which exactly decimal digit the error will occur?
- Is there a difference between Python 2 and Python 3?