Computers get math slightly wrong to make it super fast
The shortcut lets the same small memory hold galaxy-sized and atom-sized numbers, and be lightning fast doing it.

Computerphile · Floating Point Numbers - ComputerphileType 0.1 plus 0.2 into most programming languages and the result is slightly off. Instead of 0.3, you get something like 0.3000000001. The extra bit is a rounding effect from storing decimals in binary.
The method is called floating point, and it works like scientific notation. Take the speed of light, a huge number with eight zeros after it, multiplied by a tiny distance, 0.00000015. Written out longhand, that is hard work.
Written in scientific notation, the big value becomes 3 multiplied by ten raised to 8, while the small value becomes 1.5 multiplied by ten raised to minus 7. The minus 7 means the decimal point moves seven places to the left. To multiply, you multiply 3 by 1.5 to get 4.5, and add the exponents, 8 plus negative 7, to get 1. That leaves 4.5 multiplied by ten, which is 45.
That shortcut gives computers two big wins. One is speed, built up over many years until the math is now lightning fast. The other is efficiency, because the same small amount of memory can hold numbers as vast as the scale of the universe and as tiny as the scale of an atom, without needing enormous storage.
Part of the bargain is keeping only a few significant figures, the digits that matter most. Saying 3 times 10 to the 8 keeps one significant figure, a rough everyday value. Saying 2.997 times 10 to the 8 keeps four, a more careful value. The rest are dropped.
Floating point also stores only a fixed number of binary digits and cuts the rest. The limit depends on the size of the number storage a computer uses. On 32-bit computers it stores 23 digits, and on 64-bit computers, the larger storage, it keeps more digits. In binary, one tenth is a repeating fraction that goes on forever, so after 23 digits it gets cut. The computer then sees one tenth plus two tenths as not quite equal to three tenths.
Most of the time that gap disappears in the noise. A 3D game that misplaces a dot by one hundred thousandth of a pixel still puts it in the right place. A big calculation that is off by less than a molecule still looks right beyond any tolerance the real world can measure. For most everyday uses the error is too small to notice.
Questions people ask
Why can't a computer write 0.1 exactly in binary?
In binary, place values after the point are halves, quarters, eighths, and so on, and no combination adds to exactly one tenth. It becomes a repeating fraction, like one third becomes 0.333 repeating in decimal. Since the computer keeps only a fixed number of digits, it has to cut it off.
How do programmers avoid this error with money?
Programmers usually avoid floating point for money. A common fix is to count everything as whole cents or pence, using integers, and divide by 100 only to display the result. Some programming languages also offer a decimal type built for exact base 10 math.
Does 64-bit storage fix the problem?
It shrinks the error but does not remove it. Moving from 32-bit to 64-bit storage increases the kept digits, so the rounding happens much further out. One tenth is still repeating in binary, so 0.1 plus 0.2 is still not exactly 0.3.