I'm trying to calculate american Tax. The store in Florida is causing me some headaches.

There is a state tax of 6% and a city tax of 1% but only on the first $5000

It's easy to work out the tax from the price:

var total = taxRates.sum(t=>t.rate * Math.Min(t.MaxAmount??Price, Price))

This works with all tax rates and types. UK tax for eg. will only have 1 tax rate in the TaxRates list and the MaxAmount will be null.

He's the issue. I have the amount including tax and I have to come up with a one-size-fits-all method of calculating the Price ex. Tax.

Any ideas?

**What I have tried:**
I currently work out the threshold of the rate and iterate over the rates:

I.E. consider the following example for Florida:

Max Amount Rate
5000 1%
null 6%
null 1% (a fake locality tax for this demo)

the first $5000 will be taxed as 8% total. I work out the amount each 'tier' is taxed and and create the tax bands as so:

Max Amount Rate
5000 8%
null 7% (rates with the same maxamount are aggregates)

I can now tell the band threshold:

Rate Threshold Before Tax
8% 5400 5000
7% decimal.MaxValue null

so I can now iterate through this list to find the actual tax amount.

Say we have $2700. This is not higher than the first tax band so it it all taxed at 8%. 2700 / 1.08 = $2500

10000: This is over 5400 so 5400 is taxed at 8%:

4600: this is within the next band so all is taxed at 7%

= 5000 + (4600 / 1.07)

It works but it very clunky.

2500 + 8% = 2700

so

2700 / 1.08 = 2500, which is what I wrote

second :

so 5400 of the total was the 5000 charged at 8%. That means that 5400 of the 10000 has been accounted for.

this leaves 4600 to be accounted for in the next tax bracket

The issue is that when there is a limit to how much the 1% tax applies to, the total tax % will be somewhere between 7 & 8 %