Tax: taking % off number

53 Views Asked by At

I've come across a problem that I'm unsure how to solve. I'm making a software program that needs to add/remove tax from a number. It gets a little tricky though, as the tax rate is changeable.

I need a formula that can remove a % off a number. But believe me, it's not as easy as it sounds.

Look below and see my problem; (Similar to how it looks in code)

taxRate = 15%
value = 200

// Add tax
value + (value / 100 * taxRate) = 230

value = 230

// Remove tax
value - (value / 100 * taxRate) = 195.5

When I remove the tax rate I get 195.5. I need to get 200.

Does anybody know how to solve this? Any help would be much appreciated thanks!

Note I would've asked the StackoverFlow community, but I thought a mathematician would be more helpful for this problem.

1

There are 1 best solutions below

0
On BEST ANSWER

Adding a tax of $n\%$ to a base amount is the same as multiplying the base amount by $$\frac{100 + n}{100}$$ To remove the tax, just multiply the after-tax amount by $$\frac{100}{100+n}$$