Problems › JavaScript › finance
Strip VAT out of a gross price
A cashier sees the tax-inclusive total and must recover the net price the VAT was added on top of.
- Net × (100 + vat) ÷ 100 equals the gross.
- So net = gross × 100 ÷ (100 + vat), rounded down.
- A vat of zero leaves the gross unchanged.
vatReversal(grossMinor: int, vatRatePercent: int) → int
Where you start
function vatReversal(grossMinor, vatRatePercent) {
}
Worked examples
| Call | Result |
|---|---|
vatReversal(1210, 10) | 1100 |
vatReversal(1000, 0) | 1000 |
vatReversal(2000, 25) | 1600 |
vatReversal(0, 10) | 0 |
Hint
Scale the gross by 100 and divide by the tax factor.
Reference solution in JavaScript
function vatReversal(grossMinor, vatRatePercent) {
return Math.floor((grossMinor * 100) / (100 + vatRatePercent));
}