Computer Science I / Simple Modelling with Code
Practice question · Multiple choice

Storing money as a floating-point number is a well-known mistake. What actually goes wrong?

Hints
  1. Add 0.10 to itself ten times in floating point and compare with 1.00.
  2. 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.

Read the lesson: Simple Modelling with Code →

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