floating point
Floating point is how computers store numbers that have a fractional part or that span an enormous range — the size of an atom up to the distance between galaxies — using a fixed, modest number of bits. The trick is the same as scientific notation, where 0.0000123 is written 1.23 times 10^-5 and 4500000 is written 4.5 times 10^6. You store a few significant digits and, separately, an exponent that says where the decimal point goes. The point can 'float' to any scale, which is exactly where the name comes from.
A floating-point number is built from three parts: a sign (positive or negative), a significand (also called the mantissa, the significant digits), and an exponent (a power of two saying how far and which way to slide the point). The value is roughly sign times significand times 2^exponent. This contrasts with fixed point, where the binary point sits at a fixed column — fixed point is simpler and exact for money-like fractions, but it cannot stretch across a huge range the way floating point can. Floating point trades exactness for reach: it covers a vast dynamic range, but most values are stored only approximately.
That approximation is the single most important thing to understand, and it bites beginners constantly. Because the significand has only finitely many bits, many ordinary decimal fractions cannot be stored exactly — most famously 0.1, which in binary is an endless repeating fraction, just as 1/3 is endless in decimal. So 0.1 + 0.2 does not come out as exactly 0.3; it comes out as 0.30000000000000004. The honest rules that follow: never test floating-point numbers for exact equality (compare whether they are close enough instead), expect tiny rounding errors that can accumulate over millions of operations, and remember that floating point is an approximation of the real numbers, not the real numbers themselves.
The decimal 0.1 has no exact binary representation, so the computer stores the nearest value it can. That is why, in typical 64-bit floating point, 0.1 + 0.2 evaluates to 0.30000000000000004 rather than exactly 0.3.
Floating point approximates real numbers, so 0.1 + 0.2 is not exactly 0.3.
Never compare floating-point values with exact equality; test whether the difference is within a small tolerance. Rounding errors are tiny but real and can accumulate over many operations.