My colleague ran into the following problem while writing billing software.
Suppose you have a monetary amount $M$ and a tax rate $t$. For example, $M = 20.1253$ and $t = 0.07$.
The question is what are the formulas for the numbers $L$ and $H$ such that $L$ $(H)$ is the lowest (highest) number with 2 decimal places such that $T(L) = T(M)$ and $T(H) = T(M)$ with $T(x)={1\over100}[100tx + 0.5]$ where $[]$ is the greatest integer function.
In other words, what is the formula, in terms of $M$ and $t$, of the lowest and highest monetary amounts which have the same tax amount as $M$, given tax rate $t$ and rounding to the nearest penny including rounding exact halves upwards?
Given $T(M)=\frac 1{100}\lfloor 100tM+0.5\rfloor$ is the tax on $M$, we want to find $L$, the lowest price that results in $T$. We want the minimum $L$ such that $tL \ge T(M)-0.005$ or (assuming $L$ must be an exact number of cents) $L=\frac 1{100}\lceil \frac{100}t(T(M)-0.005)\rceil$. Similarly we want to find the maximum $H$ such that $tH \lt T(M)+0.005$, which is $H=\frac 1{100}\left(\lceil \frac{100}t (T(M)+0.005)\rceil-1\right)$ where the round up and $-1$ is to make sure we round $0.005$ downwards.