Discount Calculator: how it works and how to build one
Sale price after a discount, double discounts and savings. This guide explains what happens behind the button and shows the code, so you can build your own.
What it does
Find the final price after a percentage or flat discount, stack a second discount (like 50% + 20% off), add tax, and see how much you save. Or enter the sale price to find the discount percentage.
When to use it
- Shopping sales
- Setting coupon values
- Checking ‘extra’ discount claims
How to use it
- Enter the price and discount.
- Add a second discount or tax if needed.
- Read the final price and savings.
Try it free in your browser, nothing is uploaded: https://eskillsfy.com/tools/discount-calculator
How it works
Each discount multiplies the price by (1 − rate). Stacked discounts multiply, they don’t add: 50% then 20% is 0.5 × 0.8 = 0.4 of the price, so 60% off, not 70%.
Finding the discount from two prices is 1 − sale ÷ original.
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.
discount.ts (ts)
export const afterDiscounts = (price: number, ...pcts: number[]) =>
pcts.reduce((p, d) => p * (1 - d / 100), price);
export const effectiveDiscount = (price: number, final: number) => (1 - final / price) * 100;
afterDiscounts(2499, 40, 10); // 1349.46
effectiveDiscount(2499, 1349.46); // 46%
Make it production-ready
- Support a flat amount off as the first step.
Questions
Is 50% + 20% the same as 70% off?
No. It is 60% off: the 20% applies to the already halved price.
Free, runs in your browser, nothing is uploaded.