# Calculate variable in expression with Truncate function

I would like to know how to calculate MaxDigitWidth variable by using CharWidth and Pixels variables in the following expression:

CharWidth = Truncate((Pixels - 5) / MaxDigitWidth * 100 + 0.5) / 100


It should be in a form:

MaxDigitWidth = ... expression with CharWidth and Pixels variables ...


The problem is that I do not know how to get the expression in the required form because of the Truncate function.

-

Lets call MaxDigitWidth $M$, CharWidth $C$ and Pixels $P$. I assume $M,C,P\geq 0$ so that truncation is just rounding down.

Your formula amounts to $100C = \left\lfloor100\frac{P-5}{M}+\frac{1}{2}\right\rfloor$, that is $100C\leq 100\frac{P-5}{M}+\frac{1}{2} < 100C+1$ or $C-\frac{1}{200}\leq\frac{P-5}{M}<C+\frac{1}{200}$.

If $C\geq 1$ we have $\frac{200P-1000}{200C-1}\geq M>\frac{200P-1000}{200C+1}$. If a solution exists, then $M = \left\lfloor\frac{200P-1000}{200C-1}\right\rfloor$ is a solution.

Note though that there might not be any solution or there might be more than one depending on $P$ and $C$.

-
Thank you for answering, but something is wrong with your calculation. For M = 7 and P = 61, initial formula gives C = 8. But if I put P = 61 and C = 8 in your formula, I get M = Truncate(-344/80000) = 0. –  Stipo Apr 26 '13 at 13:30
I must have made a mistake somewhere, let me check. –  Abel Apr 26 '13 at 13:37
I found the mistake, correcting it now. –  Abel Apr 26 '13 at 13:40
Done correcting. I misplaced some brackets. –  Abel Apr 26 '13 at 13:44
It looks good now. I just don't get why C has to be >= 0 in order to invert the relations? Thank you Abel! –  Stipo Apr 26 '13 at 19:31
show 1 more comment