VFlash: Fast, Accurate Visual Planning via Flash Primitive Decoding
u_Unrolled
Easy10 XPfloatsbugs

Why is 0.1 + 0.2 == 0.3 False in Python?

A billing test fails because 0.1 + 0.2 == 0.3 is False. What is the right fix?

Stuck? Show the solution

Answer: B. Floats are binary approximations: compare with math.isclose, and use Decimal or integer cents for money

0.1 and 0.2 have no exact binary representation, so the sum is 0.30000000000000004. Compare floats with a tolerance; never store money as floats.

Learn the idea behind itValues, Names and Types — What a Variable Really Is