Question

I have a question on what the best way to calculate and store sales tax in the US should be. I am creating an invoice program that can have multiple line items. Here is an example of the issue I'm am running into.

One of my invoice line items looks like this.

quantity 2

amount 1133.67

tax rate 7.5% (.075)

If I add 1133.67 to 1133.67 and multiply by .075, the tax is 170.05.

However, if I take each quantity 1133.67 and apply tax to it individually first, the amount of tax totals up to 170.06.

Obviously, when I'm dealing with taxing each individual quantity, each quantity is being rounded up. But when I total each quantity and then tax the total, there is no rounding up.

I can probably solve this problem by simply editting my table field to allow for 3 decimal places instead of 2.

This may be a question only I can answer, but does it make sense to store tax amounts for each line item or no? I was thinking the data could be useful in reports later down the road.

Wondering what others are doing.

Thanks in advance.

Was it helpful?

Solution

Having worked at a successful sales tax startup, I can tell you "it depends". Local laws vary on whether you calculate sales tax at the line item or invoice level. For some discussion on the topic see:

https://money.stackexchange.com/questions/15051/sales-tax-rounded-then-totaled-or-totaled-then-rounded

I can also tell you that US sales tax is extremely complicated. There are over 10,000 jurisdictions that can levy a tax (state, county, city, and special districts such as stadium districts, metropolitan transport districts, water districts, etc.). The boundaries of those districts are not well defined an a readily available public source, and certainly do not conform to ZIP code boundaries.

If you want to get it right, your best bet is to use a sales tax calculation service. There are several SAAS solutions that are well-suited for web apps.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top