I work as an internet marketer, and half of my day is percentages. Sessions went from 12 480 to 15 210. The conversion rate fell from 3.2% to 2.7%. A channel took 1 170 of a 4 500 budget.
For years I answered those on my computer's calculator or in a spreadsheet cell I typed once and forgot. I wanted one tool that opens fast, answers while I type and asks the questions the way I ask them. So I built Percentage Calculator: seven calculators on one page, in 41 languages. It is 100% free and has no ads.
It is plain PHP, one JavaScript file and one stylesheet, with no framework and no build step. These are the parts that turned out harder than "divide by 100".
Seven questions, seven calculators
Every calculator on the page is one question I ask during a normal week. Percentage change comes first because it is the one I open most.
| Calculator | The question | An example from my week |
|---|---|---|
| Percentage change | From X to Y, by how much? | Sessions 12 480 → 15 210: +21.88% |
| Percentage of a number | What is X% of Y? | 26% of a 4 500 budget: 1 170 |
| What percent | X is what percent of Y? | 1 170 of 4 500: 26.00% |
| Add or subtract a percentage | Y plus or minus X% | A price of 100 plus 20% VAT: 120 |
| Original value | Y after a change of X%: what was it before? | 120 including 20% VAT: 100 before tax |
| Percentage difference | How far apart are X and Y? | CTR 2.4% vs 3.1% in an A/B test: 25.45% |
| Tip | Bill, tip and split | 60 plus 10%, two people: 33 each |
The last one is not marketing. It is for the dinner after a good month.
Percent change when the start is negative
The textbook formula is (new − old) ÷ old × 100. It breaks as soon as the starting value is negative, and in marketing that is not rare: profit, net revenue after refunds, a campaign that lost money.
Say a loss of 2 000 shrinks to a loss of 500. The textbook formula gives 1 500 ÷ −2 000 = −75%, which reads as things got worse. They got better. Dividing by the absolute value of the start fixes the sign:
function percentChange(from, to) { if (from === 0) return NaN; // no baseline, no percentage return (to - from) / Math.abs(from) * 100; } Now the same case is +75%. The result always shows its sign, green for up and red for down, and the worked example under the calculator shows the |…| so nobody has to guess the formula.
One more trap lives here. A CTR that goes from 2% to 3% grew by 50%, not by 1%. The 1 is percentage points. The calculator answers in percent; points are a plain subtraction.
Percentage difference is a different question
Percent change needs a starting point. When two campaigns run side by side, neither of them is the baseline. Percentage difference divides the gap by the average of the two, so the order does not matter:
function percentDifference(a, b) { const avg = (Math.abs(a) + Math.abs(b)) / 2; return avg === 0 ? NaN : Math.abs(a - b) / avg * 100; } Take a CTR of 2.4% in version A and 3.1% in version B. The change from A to B is +29.17%, the change from B to A is −22.58%, and the difference is 25.45% both ways. Absolute values in the average keep the answer positive even when one of the values is negative.
Sentences with holes in them
Each calculator is a sentence with the input fields inside it: "What is [20]% of [150]?" It reads like the question in my head, so I never wonder which box is which. It also means that a translation is not a list of strings.
Word order moves the inputs. Japanese puts the number before the percentage, and so do Hindi, Korean and Bengali:
<!-- English --> What is <input id="percent1" aria-label="Percentage">% of <input id="number1" aria-label="Number">? <!-- Japanese --> <input id="number1" aria-label="数値"> の <input id="percent1" aria-label="パーセント">% はいくつですか? The ids stay the same in every language, so one script serves all 41 pages, wherever the grammar puts the fields.
Grammar can also depend on the number itself. In Turkish, "20% of 100" is 100'ün %20'si, and the endings change with the sound of each number. A fixed sentence cannot know what you will type, so the Turkish page uses a construction that works for any number: "[100] sayısının yüzde [20] oranındaki kısmı kaçtır?" Hungarian has the same problem with its article a/az, and solves it the way Hungarian forms do: a(z).
One more detail. A <label> around a sentence with two inputs gives a name only to the first one, so a screen reader announces the second field with no name at all. Every input carries its own aria-label in the page language instead: "Starting value", "New value", "Bill amount".
Typing numbers in 41 locales
Half of the languages write 12,5 and the other half 12.5. A type="number" field treats the decimal comma differently from browser to browser; in my tests Chromium dropped it silently, so 12,50 became 1250. The fields are type="text" with inputmode="decimal", which still opens a number keyboard on phones, and the script reads the number itself.
The page language decides what a separator means:
const parts = new Intl.NumberFormat(document.documentElement.lang).formatToParts(12345.6); const decimal = parts.find(p => p.type === 'decimal').value; // "," on the German page const group = parts.find(p => p.type === 'group').value; // "." on the German page The rules that came out of it:
- A comma or a dot both work. When both appear, the last one is the decimal separator, so 1.234,56 and 1,234.56 are the same number.
- A single separator followed by exactly three digits is a thousands separator if it matches the page language. 1,000 on the English page is a thousand, and so is 1.000 on the German page. 0,125 stays a decimal.
- Spaces, apostrophes and a trailing % are ignored, and both - and − work as a minus.
- Native digits are converted: Persian ۱۲٫۵, Bengali ১২.৫, Devanagari, Thai, and the full-width digits a Japanese or Chinese keyboard produces.
The output goes the other way, through Intl.NumberFormat with the page language. The same 12.5% shows as 12,50 % in German, %12,50 in Turkish and ۱۲٫۵۰٪ in Persian, with no formatting code of my own.
1.005 is not 1.005
(1.005).toFixed(2) returns "1.00", and (2.675).toFixed(2) returns "2.67". Both numbers are stored in binary as a hair below the half, so toFixed rounds them down. A calculator that is off by one cent on round numbers loses trust fast.
The fix is to drop the binary noise before rounding:
function round2(x) { const r = Math.sign(x) * Math.round(Math.abs(Number((x * 100).toPrecision(15)))) / 100; return r === 0 ? 0 : r; // no "-0.00" } toPrecision(15) keeps the 15 digits a double can hold reliably and throws away the rest. 100.49999999999999 becomes 100.5, and only then does Math.round see it. Working on the absolute value rounds halves away from zero for negative changes too. The same core was checked against exact integer arithmetic for every cent from 0.01 to 20 000, with no difference.
Right to left, but the formula stays left to right
The Arabic, Hebrew, Persian and Urdu pages run right to left with dir="rtl" on the <html> element. The stylesheet uses logical properties such as inset-inline-end and margin-inline-start, so the language menu opens on the correct side without a second stylesheet.
The worked example under each calculator is the exception. It uses Western digits and operators, and in a right-to-left paragraph the browser reorders them into nonsense. Wrapping it in <bdi dir="ltr"> keeps it in one piece:
<p class="example">مثال: <bdi dir="ltr">(120 − 100) ÷ |100| × 100 = +20%</bdi></p> Intl.NumberFormat also adds invisible direction marks around numbers in some right-to-left locales. They are correct on screen and annoying in a spreadsheet, so the copy button strips U+200E and U+200F before it writes to the clipboard.
One list for 41 languages
Every language is a plain PHP file, and one array in languages.php describes them all: file name, lang, hreflang, native name, English name and text direction. The head of every page, the language menu and the footer list are built from that array, so a new language is one new row and one new page.
function pcHeadLinks() { $langs = pcLanguages(); $out = '<link rel="canonical" href="' . pcEsc(pcUrl($langs[pcCurrentLanguage()])) . '">'; foreach ($langs as $l) { $out .= '<link rel="alternate" hreflang="' . pcEsc($l['hreflang']) . '" href="' . pcEsc(pcUrl($l)) . '">'; } return $out . '<link rel="alternate" hreflang="x-default" href="' . pcEsc(pcBaseUrl()) . '">'; } File names can be anything; hreflang values cannot. My Simplified Chinese page is ch.php and Bengali is bd.php, but their links say zh-Hans and bn. Portuguese has two pages, pt-PT and pt-BR, because "percentagem" and "porcentagem" are searched by different people.
The language menu is a <details> element, so it works with JavaScript switched off. A 2 KB script adds a search box that matches native and English names, so "deutsch" and "german" both find the same page, and Enter opens the first match.
Small touches and the stack
Most of the work went into details I would miss if they were not there:
- The answer is a large number after an "=", in an
<output>element, with a copy button next to it. Before you type, it shows a dash, so it never looks like one more field to fill in. - A field that holds something that is not a number gets a red border and
aria-invalid, instead of a silent blank result. - A row of quick links under the title jumps to each calculator. On a phone it scrolls sideways, so it does not push the first calculator off the screen.
- Under each calculator there is a worked example with real numbers, which explains the formula faster than a paragraph.
The front end stays small: one script for all seven calculators, one stylesheet and a tiny script for the language menu, under 8 KB together when gzipped. The server side is a few plain PHP files.
What I'd like to hear
I use the calculator every week, and it has replaced the phone calculator for me. Three things I would like your opinion on:
- Translations. The 41 versions were translated with the help of AI tools and checked where I could. If you are a native speaker, especially of Amharic, Marathi, Tamil, Telugu, Swahili or Filipino, I would love a correction.
- Missing questions. If you work with numbers like I do, which percentage question do you still answer by hand? Percentage points, margin versus markup and compound growth are on my list.
- Parsing. Would you read 1.000 on a German page as one thousand, or as one with three decimals? The calculator reads it as one thousand, and I can see arguments both ways.
The calculator is at percentagecalculator.page.

