It seems that the decimal point number of Python uses the rule "IEEE754 floating point number", so the calculation result of the decimal point is as follows ... It is a specification!
>>> 0.1 + 0.1 + 0.1
0.30000000000000004
There seems to be a way to use the Decimal module to return the correct calculation result. It is a calculation example with "no rounding error" after the decimal point ↓
>>> from decimal import *
>>> Decimal('0.1') + Decimal('0.1') + Decimal('0.1')
Decimal('0.3')
Recommended Posts