Practice question · Multiple choice
Storing money as a floating-point number is a well-known mistake. What actually goes wrong?
Hints
- Add 0.10 to itself ten times in floating point and compare with 1.00.
- Ask what a bank's reconciliation process does with a total that is out by 0.0000001.
Show the answer
C. Values like 0.10 have no exact binary form, so error accumulates
Why
A tenth is a repeating fraction in binary, so every operation rounds and the errors accumulate across millions of transactions. Storing pence as integers makes the arithmetic exact, the choice of representation is a correctness decision here, not a performance one.
Practise Simple Modelling with Code
The app has 6 more questions on this lesson, and keeps your place in the course. Computer Science I is free to start.
More questions on Simple Modelling with Code
- Modelling a phone book as a dictionary rather than a list of pairs changes almost nothing about what the…
- Select every practice that the lesson recommends when modelling a problem.
- Choosing a fitting data representation is half the battle. Sort each quantity by the type that best models it.
- Order the steps of modelling a problem before writing real code.