Programming · Flashcard

Why does 0.1 + 0.2 == 0.3 evaluate to False?

  • ABinary floats can't represent those decimals exactly — tiny rounding errors remain
  • BPython compares floats by identity — equal values still live in distinct objects
  • CThe literals parse as strings first — arithmetic concatenates before converting
  • DAddition promotes the result to double precision — the comparison spans two types

Why this is the answer

0.1 and 0.2 have no exact binary representation, so the sum is 0.30000000000000004. == on floats compares values (not identity), the literals are numbers from the start, and Python floats are already double precision — there's no mixed-type promotion.

Official docs
Study in Gnoseed →