Basic Calculator: Exact Decimal Arithmetic and How Rounding Works
By FindMySum · Last reviewed
A basic calculator does four things, addition, subtraction, multiplication and division, and you might assume there is nothing left to explain. The interesting part is the one most calculators hide: how they store numbers. Many computer programs, including most web calculators, do arithmetic in binary floating point, which is why some of them report 0.1 + 0.2 as 0.30000000000000004. This calculator works in exact decimal arithmetic instead, so sums, differences, products and any quotient that terminates are shown exactly, and only a division that never ends is rounded.
Why 0.1 + 0.2 goes wrong elsewhere
Computers normally store numbers in the binary format defined by IEEE 754, the standard behind almost every processor and programming language. In binary, a fraction can only be written exactly if its denominator is a power of 2. One tenth is not: in base 2 it is 0.000110011001100…, repeating forever, in the same way that one third repeats in base 10. A 64-bit floating-point number keeps 53 binary digits, about 15 to 17 significant decimal digits, and rounds the rest. So 0.1 and 0.2 are each stored as a value a hair away from the true one, and the sum shows the error.
For most science and engineering that error is harmless, far smaller than any measurement. For money, and for anyone checking homework, it is confusing. This calculator keeps numbers as decimal digits, so 0.1 + 0.2 = 0.3 exactly, and 19.99 × 3 = 59.97 with no stray digits.
How each operation is handled
- Addition and subtraction line up the decimal points and work digit by digit, as you would on paper. The result is exact.
- Multiplication is exact too. The number of decimal places in the product is at most the sum of the decimal places in the two numbers: 4.5 × 2.2 has one plus one, and the product is 9.9.
- Division is exact when the quotient terminates, as 15.5 ÷ 2.5 = 6.2 does. When it doesn't, the result is rounded half up to 12 significant digits, so 2 ÷ 3 shows 0.666666666667.
- Division by zero is refused with a message rather than a result, because no number multiplied by 0 gives a non-zero answer.
Each number can be anywhere from −1,000,000 to 1,000,000, with decimals.
Worked example: the calculator's defaults
The calculator opens with addition, a first number of 10 and a second number of 5.
- The operation is addition, so the calculator adds 10 + 5.
- Both numbers are whole, so there are no decimal places to line up.
- The result is 15, shown as the equation 10 + 5 = 15.
Change the operation to division and the second number to 3, and the result becomes 3.33333333333: 10 ÷ 3 is 3.333… repeating, so it is rounded to 12 significant digits, with the 1-digit whole part and 11 decimal places. The equation reads 10 ÷ 3 = 3.33333333333.
Two more examples
- 0.1 + 0.2 = 0.3. This is the case binary floating point gets wrong; exact decimals get it right.
- 19.99 × 3 = 59.97. Three items at $19.99 cost exactly $59.97, with nothing to round.
Significant digits and rounding
Twelve significant digits is more than you will need for almost any everyday answer, and more than most handheld calculators show. It is a display limit, not a measure of accuracy. A result can never be more accurate than the numbers you typed: if you divide a length measured to the nearest millimetre, the extra digits after that point carry no information.
NIST's SI guide (SP 811) is a useful reference for writing results: digits are grouped in threes, and the number of digits you keep should reflect the precision of the measurement. In practice, round only once, at the end:
| Kind of result | Typical rounding |
|---|---|
| Money | To the cent (2 decimal places) |
| Lengths with a tape measure | To the nearest millimetre or 1/16 inch |
| Percentages in a report | 1 decimal place |
| Measured lab values | To the significant figures of the least precise input |
The significant figures calculator rounds to a chosen number of significant figures and explains which digits count.
What it doesn't do
The calculator performs one operation at a time. It doesn't parse a whole expression like 3 + 4 × 2, so it never has to decide the order of operations for you; you do that by choosing which pair of numbers to combine first. It also doesn't keep a running total or memory: to continue, copy the result into one of the boxes. Powers, roots and logarithms live in the exponent and logarithm calculator, and exact fractions such as one third, which a decimal display can only approximate, are better handled by the fraction calculator.
Using the result
For shopping and bills, the percentage calculator, discount calculator, sales tax calculator and tip calculator do the multi-step work for common cases. For a list of numbers rather than two, the average calculator gives the sum and the mean in one go. Every result here is a shareable link, so you can send someone the exact calculation you did.
More questions
Which divisions give a decimal that ends, and which repeat forever?
Write the division as a fraction in lowest terms. If the denominator has no prime factors other than 2 and 5, the decimal ends: 7 ÷ 8 = 0.875 and 3 ÷ 20 = 0.15. If the denominator has any other prime factor, such as 3, 7 or 11, the decimal repeats forever: 1 ÷ 3, 5 ÷ 6 and 2 ÷ 7 all do. The GCF calculator can reduce the fraction for you first.
Why doesn't 10 ÷ 3 then × 3 give back exactly 10?
Because the first result is rounded before you use it again. 10 ÷ 3 is shown as 3.33333333333, and 3.33333333333 × 3 = 9.99999999999, which is exact for the number you typed but one unit short in the last place. Where you can, rearrange the work so the division comes last (10 × 3 ÷ 3), or keep the answer as a fraction with the fraction calculator.
How should I round a result that involves money?
Do the arithmetic at full precision and round once, at the end, to the cent. Rounding each step separately can drift by a cent or more over a long calculation. For tax, the rules for when to round (per item or per invoice) are set by the tax authority and the seller's system, so a receipt can differ from your own total by a cent.
How do I work out a percentage with a basic calculator?
Divide the percentage by 100 and multiply: 15% of 80 is 0.15 × 80 = 12. To find what percentage one number is of another, divide and multiply by 100: 12 ÷ 80 = 0.15, or 15%. For percentage change, discounts and reverse percentages, the percentage calculator does the steps for you.
Why might my phone calculator show a different last digit?
Calculators differ in how many digits they keep and how they round the last one. Some show 8 or 10 digits, some round half to even instead of half up, and many work in binary floating point internally. For a division that never ends, the digits shown agree until the point where one of them stops; beyond that, neither is more correct.
Can I subtract a bigger number from a smaller one?
Yes. The result is negative: 5 − 10 = −5. You can also type negative numbers directly into either box, down to −1,000,000, and the usual sign rules apply to every operation.
Sources
This article explains how the calculator works and is general information, not financial, tax, legal or medical advice. Rules change; check the sources above or a qualified professional before you act.