The result is (in Chrome 56):
It might be surprising that an error, even if it is a relatively small one, would occur with such a simple calculation.
The reason lies with the way a computer performs floating point arithmetics. Of course, every computer internally uses 1s and 0s only, so all numbers must be converted to a binary format. For some decimal numbers this is problematic. For instance, the decimal 0.1 is infinitely recurring in binary and can therefore not be precisely expressed. Imagine the fraction 1/3 which can only approximated with 0.3333333. One tenth (or 0.1) is such a fraction in binary.
This “bug” is unfixable because it is not really a bug. The only way is to work around it. So the golden rule of working with money on computers is
Never use floating point arithmetics, use the minor denomination instead.
In our example we now calculate 3*220p which gives the correct answer.
Web & Mobile Engineer, Founder, Lean Startup Enthusiast.