如何从价格+税收中计算出金额? [英] How to I calculate an amount from the price + tax?
问题描述
我正在尝试计算美国税。在佛罗里达州的商店让我感到头痛。
州税为6%,城市税为1%但仅限于前5000美元>
从价格中计算税款很容易:
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))
这适用于所有税率和类型。例如,英国的税收。 TaxRates列表中只有1个税率,MaxAmount将为null。
他是个问题。我有包含税的金额,我必须想出一个通用的计算Price ex的方法。税。
任何想法?
我尝试过:
我目前计算出费率的门槛并迭代费率:
IE考虑以下佛罗里达州的例子:
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)
第一个5000美元将被征收8%的总税。我计算每个等级的税额,并创建税收范围:
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
所以我现在可以遍历此列表以查找实际的税额。
假设我们有2700美元。这不高于第一个税阶段,因此所有税率均为8%。 2700 / 1.08 = $ 2500
10000:超过5400,因此5400的税率为8%:
4600:这是在下一个乐队因此所有的税都是7%
= 5000 +(4600 / 1.07)
它有效但很笨重。
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.
推荐答案
5000
从价格中计算税收很容易:
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))
这适用于所有税率和类型。例如,英国的税收。 TaxRates列表中只有1个税率,MaxAmount将为null。
他是个问题。我有包含税的金额,我必须想出一个通用的计算Price ex的方法。税。
任何想法?
我尝试过:
我目前计算出费率的门槛并迭代费率:
IE考虑以下佛罗里达州的例子:
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将被征收8%的总税。我计算每个等级的税额,并创建税收范围:
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。这不高于第一个税阶段,因此所有税率均为8%。 2700 / 1.08 =
2700. This is not higher than the first tax band so it it all taxed at 8%. 2700 / 1.08 =
这篇关于如何从价格+税收中计算出金额?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!