DEV Community

RemoveVAT
RemoveVAT

Posted on Edited on

The VAT maths mistake hiding in almost every invoice tool

Here is a bug I keep finding in invoice tools, spreadsheet templates and "quick VAT calculators" — including, briefly, our own first prototype.

A customer pays £120 for something with 20% VAT. Quick: how much of that is VAT?

The instinctive answer is £24 — twenty per cent of £120. It is also wrong. The VAT inside £120 is £20, and the net is £100. Twenty per cent was added to the net (£100 × 1.2 = £120), so taking twenty per cent of the gross overstates the tax by a fifth. Multiply that error across a year of invoices and a business files the wrong return with total confidence.

The fix is one division

To strip VAT out of a gross figure you divide by 1 + rate, you never subtract the percentage:

function removeVat(gross, ratePercent) {
  const net = gross / (1 + ratePercent / 100);
  return { net: round2(net), vat: round2(gross - net) };
}
Enter fullscreen mode Exit fullscreen mode

Adding VAT is the mirror image (multiply by 1 + rate), and the UK's Flat Rate Scheme is a third shape again: a sector percentage applied to VAT-inclusive turnover, which is why comparing the scheme against standard accounting needs both calculations side by side before the numbers mean anything.

We open-sourced the data and the snippet

VAT code is only as good as its rates table, so we published ours: UK and EU standard and reduced rates plus the UK thresholds (£90,000 registration, checked against GOV.UK; EU rates against the European Commission), as CSV and JSON, with the three calculator functions, in our public repo: uk-eu-vat-rates. Corrections and issues welcome — rates change, and a wrong rate in a copied snippet propagates silently.

The no-code version

The same maths runs in the browser at RemoveVAT — a free vat calculator uk sole traders and bookkeepers use to add or remove VAT at any rate, compare the Flat Rate Scheme against standard VAT, work out reverse charge, generate VAT invoices, check UK VAT numbers and run bulk figures. No sign-up, nothing uploaded.

If you maintain anything that touches VAT: grep your codebase for * 0.2 applied to a gross amount today. That search has a genuinely high hit rate.

Top comments (0)