Method Deck / currency

Price with VAT or sales tax

Adds a tax rate to an exclusive price, or removes a tax rate from an inclusive price, given a stated tax percentage.

Published for review. The Founder is checking every card himself; anything he strikes comes down the same hour.

Try it

Inputs

Outputs

Steps

  1. Convert the tax rate to a decimal: r = tax_rate_percent / 100.
  2. If direction is "add": result = price * (1 + r) (price is treated as the tax-exclusive amount).
  3. If direction is "remove": result = price / (1 + r) (price is treated as the tax-inclusive amount).
  4. Round result to 2 decimal places.

Constants

None.

Sources

Worked example and test vectors

NameInputsAnswer
worked example{"price":100,"tax_rate_percent":20,"direction":"add"}120.00
test vector: remove tax recovers the exclusive price{"price":120,"tax_rate_percent":20,"direction":"remove"}100.00
test vector: fractional tax rate{"price":50,"tax_rate_percent":8.25,"direction":"add"}54.13

Published card