DEV Community

Prime Voucher
Prime Voucher

Posted on

How I Built 10 Shopping Calculators for a UK Voucher Site

Voucher sites usually stop at listing codes. But shoppers keep asking the same questions: Is 20% off better than £10 off? Does a voucher stack with the sale? Should I pay delivery or add another item?

So for PrimeVoucher, a UK voucher codes site, I built a set of small calculators that answer those questions. Here's the maths behind a few of them.

1. Stacked discounts multiply, they don't add

function stackedDiscount(price, ...percents) {
  const finalPrice = percents.reduce((p, pct) => p * (1 - pct / 100), price);
  return { finalPrice, totalPercentOff: (1 - finalPrice / price) * 100 };
}

stackedDiscount(100, 30, 20); // { finalPrice: 56, totalPercentOff: 44 }
Enter fullscreen mode Exit fullscreen mode

30% + 20% is 44% off, not 50%. Live version: stacked discount calculator.

2. % off vs £ off has a break-even point

A 15% code beats a £10 code once the basket passes £66.67 (10 ÷ 0.15).

const compareVouchers = (basket, pct, pounds) =>
  basket * (pct / 100) >= pounds ? 'percent' : 'pounds';
Enter fullscreen mode Exit fullscreen mode

Live version: voucher comparison calculator.

3. UK VAT both ways

const addVat = (net) => net * 1.2;
const removeVat = (gross) => gross / 1.2; // not gross * 0.8!
Enter fullscreen mode Exit fullscreen mode

A common mistake is removing VAT by taking 20% off the gross price. Live version: VAT calculator.

4. Price per unit for multipacks

const pricePerUnit = (price, qty) => price / qty;
Enter fullscreen mode Exit fullscreen mode

Simple, but it's the one supermarket shoppers use most. Live version: price per unit calculator.

Lessons learned

  • Round only at the end. Rounding between stacked steps creates penny errors.
  • Explain the result. Each calculator page has a short guide and FAQs, because a number alone doesn't build trust.
  • Keep it free and sign-up-free. People bookmark tools they can use instantly.

The full set of ten is on the PrimeVoucher calculators page, and the core functions are open source on GitHub.

Top comments (0)