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.
vat_reversal(gross_minor: int, vat_rate_percent: int) → int
Where you start
def vat_reversal(gross_minor: int, vat_rate_percent: int) -> int:
Worked examples
| Call | Result |
|---|---|
vat_reversal(1210, 10) | 1100 |
vat_reversal(1000, 0) | 1000 |
vat_reversal(2000, 25) | 1600 |
vat_reversal(0, 10) | 0 |
Hint
Scale the gross by 100 and divide by the tax factor.
Reference solution in Python
def vat_reversal(gross_minor: int, vat_rate_percent: int) -> int:
return gross_minor * 100 // (100 + vat_rate_percent)