# Number of decimals to round to after division so that reversing the operation is precise

I'm dividing number A (positive, with up to 2 decimal places) by another number B (positive, up to 3 decimal places) to arrive at my result, C.

I'd like to round C to the fewest decimal places so that multiplying it back with B is always equal to A after rounding to 2 digits.

Is there a method for determining how many decimal places are needed in C for the assumption:

round(C * B, 2) = A

to always be true?

I don't think significant figures/digits are important here, as I'm not concerned with measurement precision in any of the results -- I just need the fewest decimal places in C to satisfy that assumption. It may also be worth noting that I can't change the value of A or of B.

My gut tells me the answer is simply the total of the decimal places in A and B (5), but I can't seem to find anything online that covers rounding then reversing the operations.

Ultimately, I'm hoping to find the method for determining this number of decimal places so that perhaps I can variably set the number of decimal places to include in C based on whether there happen to be trailing zeroes in the other values.

• Your terminology "decimals" is not standard. Do you mean significant figures, or decimal places? E.g. 12.345 is five significant figures and three decimal places. Apr 15, 2016 at 12:27
• Sorry, decimal places in all cases. Apr 15, 2016 at 19:22

Am I right in thinking that $A$ and $B$ are exact to 2 and 3 decimal places respectively? That being the case, we only need to worry about $C$.

Let's write it as $C=c+\delta c$, where $\delta c$ is the bit you're wanting to discard. We have

\begin{align} B(c+\delta c)&=A \\ Bc&=A-B\delta c \end{align} Therefore $Bc$ will round back to $A$ as required provided $|B\delta c|<0.005$. If $C$ is rounded to $n$ decimal places, $|\delta c|\le 0.5 \times 10^{-n}=0.005\times 10^{-(n-2)}$, so we just need \begin {align} |B|&<10^{n-2} \\ n&>2+\log_{10}|B| \end {align}

So contrary to what you thought, the number of digits in $B$ turns out to be key.

• Excellent! Thank you. So in my case, if I can safely assume B will never have more than 4 digits (e.g. 9.999 max), then rounding to 3 decimals should be sufficient. Apr 15, 2016 at 20:14
• Yes that sounds right! Apr 15, 2016 at 22:27

How many decimals to the left of C depends upon how many are to the right of B. Similarly, the number of decimals you need to the right of C depends upon the size of B.

$(C + \epsilon_c)*(B+\epsilon_b) = CB + C \epsilon_b + B\epsilon_c$ (the $\epsilon_b\epsilon_c$ term is insignificant and can be ignored)

If you want $C \epsilon_b + B\epsilon_c < 0.01$ then $\epsilon_b < 0.005/C$ and $\epsilon_c < 0.005/B$