Toolmingo
Guides5 min read

Discount Calculator: How to Calculate a Discount and Sale Price

Learn how to calculate a discount percentage, find the sale price, and work backwards from a discounted price. Includes code examples in JavaScript, Python, Go, and PHP.

Discount Calculator: How to Calculate a Discount and Sale Price

Whether you're shopping a 30%-off sale, building an e-commerce checkout, or writing a point-of-sale system, discount calculations follow a handful of simple formulas. This guide covers all of them — including how to work backwards from a sale price to find the original price or the discount percentage.


The Three Core Discount Formulas

1. Discount Amount

Discount amount = Original price × (Discount % / 100)

A €80 jacket with a 25% discount:

Discount amount = 80 × 0.25 = €20

2. Sale Price

Sale price = Original price − Discount amount
           = Original price × (1 − Discount % / 100)

Same jacket:

Sale price = 80 × (1 − 0.25) = 80 × 0.75 = €60

3. Savings as a Percentage (Reverse Calculation)

When you know the original and sale price but want the percentage:

Discount % = ((Original price − Sale price) / Original price) × 100

A €120 item sold for €90:

Discount % = ((120 − 90) / 120) × 100 = 25 %

Working Backwards: Original Price from Sale Price

Shops sometimes advertise "pay €45, was €?" You can find the original price if you know the discount rate:

Original price = Sale price / (1 − Discount % / 100)

Item on sale for €45 at 40% off:

Original price = 45 / (1 − 0.40) = 45 / 0.60 = €75

Quick-Reference Table

Original Discount % Discount Amt Sale Price Savings
€100 10 % €10 €90 10 %
€100 25 % €25 €75 25 %
€100 50 % €50 €50 50 %
€250 15 % €37.50 €212.50 15 %
€79.99 20 % €16.00 €64.00 20 %
€1 200 33 % €396 €804 33 %

Code Examples

JavaScript

function discountAmount(originalPrice, discountPercent) {
  return originalPrice * (discountPercent / 100);
}

function salePrice(originalPrice, discountPercent) {
  return originalPrice * (1 - discountPercent / 100);
}

function discountPercent(originalPrice, salePrice) {
  return ((originalPrice - salePrice) / originalPrice) * 100;
}

function originalPrice(salePrice, discountPercent) {
  return salePrice / (1 - discountPercent / 100);
}

// Round to 2 decimal places for currency
const round2 = (n) => Math.round(n * 100) / 100;

console.log(round2(salePrice(80, 25)));     // 60
console.log(round2(discountPercent(120, 90))); // 25
console.log(round2(originalPrice(45, 40)));    // 75

Python

from decimal import Decimal, ROUND_HALF_UP

def discount_amount(original: float, percent: float) -> Decimal:
    o = Decimal(str(original))
    p = Decimal(str(percent)) / 100
    return (o * p).quantize(Decimal("0.01"), rounding=ROUND_HALF_UP)

def sale_price(original: float, percent: float) -> Decimal:
    o = Decimal(str(original))
    p = Decimal(str(percent)) / 100
    return (o * (1 - p)).quantize(Decimal("0.01"), rounding=ROUND_HALF_UP)

def discount_percent(original: float, sale: float) -> Decimal:
    o, s = Decimal(str(original)), Decimal(str(sale))
    return ((o - s) / o * 100).quantize(Decimal("0.01"), rounding=ROUND_HALF_UP)

def original_price(sale: float, percent: float) -> Decimal:
    s = Decimal(str(sale))
    p = Decimal(str(percent)) / 100
    return (s / (1 - p)).quantize(Decimal("0.01"), rounding=ROUND_HALF_UP)

print(sale_price(80, 25))           # 60.00
print(discount_percent(120, 90))    # 25.00
print(original_price(45, 40))       # 75.00

Go

package main

import (
	"fmt"
	"math"
)

func round2(v float64) float64 {
	return math.Round(v*100) / 100
}

func discountAmount(original, percent float64) float64 {
	return round2(original * percent / 100)
}

func salePrice(original, percent float64) float64 {
	return round2(original * (1 - percent/100))
}

func discountPercent(original, sale float64) float64 {
	return round2((original-sale) / original * 100)
}

func originalPrice(sale, percent float64) float64 {
	return round2(sale / (1 - percent/100))
}

func main() {
	fmt.Println(salePrice(80, 25))           // 60
	fmt.Println(discountPercent(120, 90))    // 25
	fmt.Println(originalPrice(45, 40))       // 75
}

PHP

function discountAmount(float $original, float $percent): float {
    return round($original * $percent / 100, 2);
}

function salePrice(float $original, float $percent): float {
    return round($original * (1 - $percent / 100), 2);
}

function discountPercent(float $original, float $sale): float {
    return round(($original - $sale) / $original * 100, 2);
}

function originalPrice(float $sale, float $percent): float {
    return round($sale / (1 - $percent / 100), 2);
}

echo salePrice(80, 25);           // 60
echo discountPercent(120, 90);    // 25
echo originalPrice(45, 40);       // 75

Stacking Multiple Discounts

When two discounts are applied in sequence (e.g., a store discount then a coupon), they do not simply add up:

Final price = Original × (1 − d1/100) × (1 − d2/100)

Example — 20% off, then an extra 10% off:

Final = 100 × 0.80 × 0.90 = €72

The combined saving is 28%, not 30%. This is called compounding discounts (or "successive discounts"). Retailers often present them as additive to make the deal sound bigger — the customer actually saves less than the sum suggests.

To find the single equivalent discount rate:

Equivalent % = (1 − (1 − d1/100) × (1 − d2/100)) × 100

For 20% + 10%: (1 − 0.80 × 0.90) × 100 = 28 %


Markup vs Discount

A markup is the percentage added to the cost price to get the selling price; a discount is the percentage subtracted from the selling price. They are not interchangeable:

Scenario Formula Example (cost €60, mark 25%)
Markup on cost Sell = Cost × (1 + markup/100) €60 × 1.25 = €75
Discount off sell Sale = Sell × (1 − disc/100) €75 × 0.75 = €56.25

A 25% markup followed by a 25% discount does not return to the cost price — it gives €56.25, a €3.75 loss. Common retail trap.


Frequently Asked Questions

What is the formula for a discount?
Sale price = Original price × (1 − discount% / 100). Multiply the original by the complement of the discount percentage.

How do I calculate a 20% discount?
Multiply the original price by 0.80 (i.e., 1 − 0.20). A €50 item at 20% off costs €50 × 0.80 = €40.

How do I find the original price after a discount?
Divide the sale price by (1 − discount% / 100). If you paid €60 at 25% off: €60 / 0.75 = €80.

What's the difference between discount and percentage off?
They are the same thing expressed differently. "25% discount" and "25% off" both mean you save 25% of the original price.

Do two 50% discounts equal 100% off?
No. Two successive 50% discounts give: 1 × 0.50 × 0.50 = 0.25, so you pay 25% of the original — a 75% total saving, not 100%.

How do I calculate the discount percentage from two prices?
Discount % = ((Original − Sale) / Original) × 100. If something was €200 and now costs €150: ((200 − 150) / 200) × 100 = 25 %.


For quick calculations use the Discount Calculator — enter any two values and it solves for the third in real time.

Related tools

Keep reading

All Toolmingotools are free & run in your browser

No sign-up, no upload, no watermark. Your files never leave your device.

Browse all tools