Percentage Calculator: how it works and how to build one
X% of Y, percentage change, and what percent X is of Y. This guide explains what happens behind the button and shows the code, so you can build your own.
What it does
Three calculators in one: find a percentage of a number, find what percent one number is of another, and find the percentage increase or decrease between two numbers. Results update as you type.
When to use it
- Discounts and tips
- Marks and exam results
- Growth figures in reports
How to use it
- Pick the calculation you need.
- Type the numbers.
- Read and copy the answer.
Try it free in your browser, nothing is uploaded: https://eskillsfy.com/tools/percentage-calculator
How it works
Three formulas cover almost every percentage question: X% of Y = X ÷ 100 × Y; X is what % of Y = X ÷ Y × 100; and percentage change = (new − old) ÷ old × 100.
Note that a 50% rise followed by a 50% fall doesn’t return to the start, because the second percentage is of a bigger number.
Build it yourself
Here is the core of the tool. It has no dependencies unless noted, so you can paste it into any TypeScript or JavaScript project.
percent.ts (ts)
export const percentOf = (pct: number, of: number) => (pct / 100) * of;
export const whatPercent = (part: number, whole: number) => (part / whole) * 100;
export const percentChange = (from: number, to: number) => ((to - from) / Math.abs(from)) * 100;
percentOf(18, 2500); // 450
whatPercent(450, 1800); // 25
percentChange(80, 100); // 25
Make it production-ready
- Handle division by zero with a clear message.
Questions
How is percentage change worked out?
(new − old) ÷ old × 100. Going from 80 to 100 is a 25% increase.
Free, runs in your browser, nothing is uploaded.