Discount Calculator: Why "Extra 20% Off the Sale Price" Isn't 50% Off
Last holiday season our small storefront ran a "30% off everything" sale and, on top of that, emailed a coupon for "an extra 20% off at checkout." Within a day, support had a pile of tickets that all said the same thing: a $120 jacket should be $60 with half off, so why did the checkout page show $67.20?
The answer, of course, is that the two discounts multiply instead of add. But explaining that one-on-one, over and over, got old fast. So I wrote the math down three ways: a Python script for the team, a spreadsheet formula for support, and a browser page for anyone who just wants the number. Here's all three, plus the traps I hit along the way.
The scenario
The numbers from one real ticket:
- Jacket price: $120.00
- Store sale: 30% off
- Coupon: extra 20% off (applied to the sale price, per the terms)
- Customer expected: $60.00 (30% + 20% = 50% off)
- Checkout showed: $67.20
$67.20 is correct. 30% off leaves 70% of the price; the extra 20% takes 80% of that. The total discount is 1 − (0.7 × 0.8) = 44%, not 50%. On a $120 jacket that's $18.80 more than the customer guessed, which is exactly the size of disappointment that turns into a ticket.
Method 1: Python with Decimal (Python 3.11.1)
Money in floats is asking for trouble, so I used Decimal. This is the script I ended up pasting into support replies (Python 3.11.1, standard library only):
# stack_discounts.py — Python 3.11.1 from decimal import Decimal, ROUND_HALF_UP def final_price(base: Decimal, percents: list[Decimal]) -> Decimal: price = base for p in percents: price = price * (Decimal("100") - p) / Decimal("100") return price.quantize(Decimal("0.01"), rounding=ROUND_HALF_UP) base = Decimal("120.00") print(final_price(base, [Decimal("30"), Decimal("20")])) # 67.20 print(base * Decimal("50") / Decimal("100")) # 60.00 (what the customer expected) effective = 100 - (100 - 30) * (100 - 20) / 100 print(f"effective discount: {effective}%") # effective discount: 44.0% Running it prints 67.20, 60.00, and 44.0%. That last line became the one-liner I put in the coupon terms page. The Python decimal docs cover the rounding modes if you need banker's rounding instead of ROUND_HALF_UP.
Method 2: JavaScript (Node 22.13.1)
Our checkout is JavaScript, so I reproduced the same math there (Node 22.13.1):
// discount.js — Node 22.13.1 const base = 120.0; const stacked = base * 0.7 * 0.8; console.log(stacked); // 67.2 console.log(stacked.toFixed(2)); // "67.20" console.log(100 - 0.7 * 0.8 * 100); // 44.00000000000001 Same result, one new problem: 100 - 0.7 * 0.8 * 100 comes out as 44.00000000000001. Harmless here, but floats will bite you on prices that don't divide cleanly. A classic from our own test suite: 4.35 * 0.9 evaluates to 3.9149999999999996, and (4.35 * 0.9).toFixed(2) returns "3.91", not the 3.92 you'd get by rounding half up on paper. The usual fix is to work in integer cents and round once at the end, or reach for a decimal library. The toFixed docs on MDN spell out why the rounding is not what you'd expect from school math.
For support staff, the plain-spreadsheet version ended up being enough:
=ROUND(120 * (1 - 0.30) * (1 - 0.20), 2) → 67.20 Method 3: a browser tool when you just need the number
Most of the time nobody wants a script. When a customer emails "what will I actually pay?", support opens a free online discount calculator, types in the original price and the discount, and reads off the final price and the savings. For stacked coupons you run it twice: take the first result as the new base for the second discount. It runs entirely in the browser, so there's nothing to install and nothing uploaded, which matters when the conversation involves someone's actual order.
I also keep this browser-based tool pinned while writing promo copy, because it catches the "50% off!" claim before it ships instead of after.
Three traps worth knowing
1. Adding percentages instead of stacking them. This is the whole ticket pile in one bullet. 30% + 20% is not 50% off; the real discount is 44%. I verified the direction the other way too: a 20% coupon followed by a 30% sale also lands on $67.20; stacking is commutative, which surprises people but follows straight from multiplication.
2. Trusting toFixed(2) to round "correctly." The 4.35 * 0.9 case above produced "3.91" where a human would write 3.92, because the float closest to 3.915 is actually slightly below it. If your receipts must match the accountant's, compute in cents with integers: Math.round(435 * 90 / 100) gives 392 cents. Same input, different cent, real dispute.
3. Rounding per item versus at cart level. A cart with $9.99, $14.99, and $7.25 at 15% off rounds to $27.39 if you round each discounted item and sum, but $27.40 if you sum first and round once. One cent, but our payment provider rejected a settlement batch over exactly this class of mismatch. Pick one policy, write it down, and apply it everywhere. And check your jurisdiction: in some places sales tax is computed on the pre-discount price, so the receipt legitimately shows more than "price after discount" suggests. That's another source of tickets that no amount of discount math fixes.
Quick summary
| Situation | Correct math | $120 base |
|---|---|---|
| Single 30% off | base × 0.70 | $84.00 |
| 30% then extra 20% | base × 0.70 × 0.80 | $67.20 |
| "50% off" (what customers expect) | base × 0.50 | $60.00 |
| Effective stacked discount | 1 − 0.70 × 0.80 | 44% |
The one-line takeaway: stacked discounts multiply, so convert each to its remainder and multiply those. Whether you do it in Python, in a spreadsheet, or in the discount calculator, do it before the coupon email goes out. Future-you in the support inbox will be grateful.
More free browser-based utilities at utilvy.com.