3
$\begingroup$

I have a system where is user can enter a price (without tax) and a tax rate. I then calculate the total cost of the item.

Example:

Price:100.00

Tax percent: 10%

Final price: 110.00 = (100 + (100* (10/100))

I have got a request to work backwards and start with the final price and tax and determine the price without tax.

In my system I store only price without tax and tax percent.

For example if a user wants a final price of 30.00 and a tax percent of 8.25

The starting price in this case has more than 2 decimals.

How many decimals do I need to store to allow for tax inclusive pricing for all possibilities?

$\endgroup$

2 Answers 2

1
$\begingroup$

I'm assuming you only need your output price accurate to two decimals. The meaning of "X is accurate to $n$ decimals" is that X is an approximation, but the difference between it and the true value is less than $\displaystyle\frac{5}{10^{n+1}}$ (we want to say $1/10^n$ but we have to account for rounding).


Technical details:

What you are saying in more technical language is that you want to calculate the error $\delta$ allowed on the input to have an error $\epsilon<\frac{1}{200}$ on the output.

Suppose the tax rate is $r$%, and the true price of a customer's purchase is $p$. A "perfect computer" would take $p$ as an input and give $p+\frac{r}{100}p$ as an output. Our real computer will use the same function but will not take in $p$ but instead some approimation $\hat p$. So the fully symbolic question is to find a $n$ such that $$\left|p-\hat{p}\right|<\frac{5}{10^{n+1}} \qquad\Longrightarrow\qquad \left|p+\frac{r}{100}p-\hat{p}-\frac{r}{100}\hat p\right|<\frac{1}{200}$$

The left side of the right equation is: $$\left|\left(p-\hat p\right)\left(1+\frac{r}{100}\right)\right| = \left|p-\hat p\right|\left(1+\frac{r}{100}\right)<\frac{5}{10^{n+1}}\left(1+\frac{r}{100}\right)$$

So if we could only get $\frac{5}{10^{n+1}}\left(1+\frac{r}{100}\right)<\frac{1}{200}$ then we'd be golden. Solving for $n$: $$\left(1+\frac{r}{100}\right)<\frac{10^{n+1}}{1000}$$ $$\left(1+\frac{r}{100}\right)<10^{n-2}$$ $$\log_{10}\left(1+\frac{r}{100}\right)<n-2$$ $$2-\log_{10}\left(\frac{100+r}{100}\right)<n$$ $$\log_{10}\left(100+r\right)<n$$

Interest rates are almost surely less than $100$% so $n=3$ suffices here. Note that multiplying $p$ by a constant adds its logarithm to the left side. Summing over many choices for $p$ is bounded by multiplying the number of terms in the summation by the largest $p$, so this is also logarithmic.


The bottom line:

There's not quite enough information to solve the problem but there's enough for a recommendation. Start with three decimals, and add a few more according to these rules:

  • How many of each kind item is a typical customer going to buy? If it's 1-8 then add nothing, if 9-98 then add one decimal, two decimals for 99-998 etc.
  • How many different items are they likely to buy? Use the same scale.
  • Add one more if you have reasonably frequent bulk orders that exceed the above estimations.
$\endgroup$
0
$\begingroup$

As you've shown, given a initial price $p_i$ and tax percentage $t$, we directly have that the final price $p_f$ is $p_f=p_i\left(1+\frac{t}{100}\right)$.

Given that, can you solve $p_i$ in terms of $p_f$ and $t$?

$\endgroup$
1
  • $\begingroup$ I know how to calculate it, I am wondering how many levels of decimal precision I need in order to reliable calculate the price without tax. $\endgroup$ Commented Oct 15, 2013 at 1:07

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .