Jun-12-2020, 08:22 AM
The floating-point is a representation in binary system, which cannot represent all decimals.
It's mathematically proofed.
Decimal could help, but keep in mind, that it's much slower than floating-point arithmetic.
This will not eliminate the error, but you can get closer to a result.
It's mathematically proofed.
Decimal could help, but keep in mind, that it's much slower than floating-point arithmetic.
from decimal import Decimal print(Decimal(100) * Decimal("1e-6")) print(Decimal(100e6) * Decimal("1e-6"))
Output:Decimal('0.000100')
Decimal('100.000000')
If you need floating-point with higher precision and fast, then try mpmath.This will not eliminate the error, but you can get closer to a result.
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
All humans together. We don't need politicians!