Take the 2-minute tour ×
Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

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.

share|improve this question

1 Answer 1

up vote 0 down vote accepted

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$.

share|improve this answer
    
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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.