Quant Memo
Coding/●●●●●

A settlement total that is off by a penny, and why floats caused it

Asked at Jane Street, Citadel

A settlement system adds up 1,000,000 transactions of $0.01 each. The books say the total should be exactly $10,000.00. The code returns something slightly off:

>>> total = 0.0
>>> for _ in range(1_000_000): total += 0.01
>>> total
10000.000000181902

Auditors do not accept "close." Explain why the float total drifts, and implement a summation that is exact to the cent.

Your answer

This one is open-ended. Work it through, then check your reasoning against the full solution.

More Coding questions