About Unpreciseness of Floats

Float type is implemented according to the IEEE 756 Standard established in the ancient 1985, and has preciseness flaws because of how floats are operated by CPU. For example:

1
2
>>> 0.1 * 3
0.30000000000000004

For financial or other operations where preciseness matters, use Decimal instead:

1
2
3
>>> from decimal import Decimal
>>> Decimal("0.1") * 3
Decimal('0.3')

Tips and Tricks Programming Architecture Python 3