statable Statistics for study and research

Floating-point number and rounding error

Computers store decimal numbers as floating-point numbers with limited precision. Some values such as 0.1 cannot be represented exactly. This produces tiny rounding errors that disturb comparisons for equality.

Example: In many programs 0.1 + 0.2 is not exactly equal to 0.3. A test for equality reports “false”.

Caution: Numbers should be tested for equality with a small tolerance. The display often shows rounded values while the calculation uses more digits.

Related

Open in Statable