Why does 0.1 plus 0.2 not equal 0.3 in Python?
Numbers and arithmetic
Audio flashcard · 0:18Nortren·
Why does 0.1 plus 0.2 not equal 0.3 in Python?
0:18
This is a property of binary floating point arithmetic, not specific to Python. The decimal numbers 0.1 and 0.2 cannot be represented exactly in binary, so their sum has a tiny rounding error. For exact decimal arithmetic, use the Decimal class from the decimal module or Fraction from the fractions module.
docs.python.org