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
C# needs a compiler and Drill does not host one yet, so this page is the reference rather than an exercise: the problem, worked examples, and the solution in full. To type it out, the same problem runs in Python.
Where you start
public int VatReversal(int grossMinor, int 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 C#
public int VatReversal(int grossMinor, int vatRatePercent) {
return (grossMinor * 100) / (100 + vatRatePercent);
}