Search code examples
e-commerceformulapercentage

How to calculate the original value given a percentage inclusive value?


We have a shopping cart that is used in different places, therefore the tax is stored in a config file, presently in New Zealand it is 15%, so in the config file we are storing .15 but this number can be changed, so I need to formulas to not rely on this value being a specifc value!

We also have another key that stores whether the prices we are storing are tax inclusive or exclusive (users are picky, some want to enter prices with, some without :/).

So, if the key contains inclusive it means that the prices are stored containing the gst content as well.

if the key contains exclusive, well. you get the idea.

Anyway.

I am having a wee bit of an issue wrapping my head around the formulas to get the tax inclusive and exclusive prices.

Let's use these variables.

$tax_type = 'exclusive'
$product_price = 150
$tax_amount = 0.15

If a product has it's price stored tax exclusive thats easy.

Exclusive price = $product_price = 150
Inclusive price = $product_price + ($product_price*$tax_amount) = 150 + (150*0.15)

But if a product has it's price stored tax inclusive that's where I get confused.

So, the variables now become

$tax_type = 'inclusive'
$product_price = 172.5
$tax_amount = 0.15

The tax inclusive price is now $product_price. But how do I calculate the tax exclusive price?

On the IRD website, it states you can use $product_price - ($product_price*3/23) but I imagine that is only for tax at 15%?


Solution

  • The formula is straight forward:

    Inclusive = Exclusive * (1 + tax rate)

    Where the tax rate is some decimal such as the 0.15 you posted. Via algebra then, the exclusive price would be:

    Exclusive = Inclusive / (1 + tax rate)