Free Handy Tools

Calculator

0

A plain calculator that behaves predictably

This is the four-function calculator: add, subtract, multiply, divide, percent, sign change and a decimal point, with a twelve-digit display. It is deliberately not a scientific calculator — there are no brackets and no operator precedence, because a pocket calculator has never had them and adding them silently would change what the same keystrokes mean.

It takes the keyboard as well as the buttons: digits, a full stop or comma for the decimal point, the four operator keys, Enter or equals to evaluate, Backspace to delete a digit and Escape to clear.

How chained operations are evaluated

Each operator key evaluates whatever is already pending before storing the new one. So 2 + 3 + 4 shows 5 as soon as the second plus is pressed and 9 on equals, rather than dropping the first pair. Because there is no precedence, 2 + 3 × 4 is evaluated strictly left to right and gives 20, not 14. If you want 14, you want the scientific calculator, where multiplication binds tighter than addition.

Results are trimmed to twelve significant digits before display, which removes the binary floating-point artefacts that otherwise leak through: 0.1 + 0.2 shows 0.3 rather than 0.30000000000000004. Anything below 1e−9 or at or above 1e12 switches to exponential notation instead of filling the display with zeros.

The percent key, which is not what most people expect

The percent key follows the iOS convention, and it does two different things depending on the pending operation.

  • With a pending + or −, the percentage is taken of the previous number. 200 + 10 % displays 20, and equals gives 220. That is what you want for adding a tip or a tax.
  • With a pending × or ÷, or with no pending operation at all, it is a plain division by a hundred. 200 × 10 % displays 0.1, and equals gives 20.

Both are defensible and neither is universal — several desktop calculators do the opposite for at least one of these cases. If a percentage result looks wrong, this is almost always why.

Limits and error handling

Entry is capped at twelve digits, so a thirteenth keystroke is ignored rather than producing a number the display cannot show honestly. Division by zero produces "Error" rather than infinity, and the next digit you type starts a fresh calculation — the error state cannot be operated on.

There is no memory, no history tape, and no way to edit an expression once entered; Backspace removes the last digit of the current entry only. Underneath, the arithmetic is IEEE 754 double-precision floating point, which is exact for integers up to about 9 quadrillion and approximate for most decimal fractions. The twelve-digit trim hides that in ordinary use, but it does not remove it: money calculations that must be exact to the cent belong in a system that works in integer cents.

Calculator questions

Why does 2 + 3 × 4 give 20 here and 14 elsewhere?

Because a basic calculator evaluates in the order you press the keys, while a scientific one applies operator precedence. Both are correct for what they are. Use the scientific calculator on this site if you need brackets and precedence.

How do I add tax to a price?

Type the price, press +, type the tax rate, then %, then equals. For 8% on $50: 50 + 8 % = gives 54, because the percent key takes 8% of 50 — that is 4 — while an addition is pending.

Why did my long decimal get shortened?

The display trims to twelve significant digits to hide floating-point noise. If you need more precision than that, you need a calculator working in a different number representation, not a longer display.