# Formula To Determine Percentage Between Two Numbers After Certain Threshold

I have a formula I use to determine how opaque some validation text should be based upon the length of a user's input compared to the maximum lenth allowed. I want to modify it so that the "ramping up" of the opacity percentage only starts when they are at 80% of max, and then scales up proportionally from there.

Here is my current function:

OpacityPercentage = CharactersEntered / MaxCharacters

Therefore, if I have MaxCharacters of 50, then the opacity is as follows:

• 30 chars = 60%
• 40 chars = 80%
• 41 chars = 82%
• 45 chars = 90%
• 50 chars = 100%

What I want is for the opacity to be 0% until I get to 80% of max, then scale up from there. So I would want the table to look as follows:

• 30 chars = 0%
• 40 chars = 0%
• 41 chars = 10%
• 45 chars = 50%
• 50 chars = 100%

I thought this would be simple, but I can't seem to figure out what I need to change in my existing formula. Any advise is appreciated!

-
Could you just take the maximum of $0$ and $( \text {CharactersEntered}-40)\cdot 10$? –  David Mitra Feb 17 '12 at 23:03
That's it! I knew it was simple, but I couldn't wrap my head around it. If you would, can you post your comment as an answer and I'll accept it. Thanks again! –  bmccleary Feb 17 '12 at 23:17

Could you just take the maximum of $0$ and $(\text{CharactersEntered}−40)\cdot10$ (percent)?
If you wanted to start the percentages off at $x$ and have them increase linearly to $100$ at $50$ characters, then you are adding $(100-x)/10$ percent for each character over $40$. The number of characters over 40 is $$I=\text{max}\{(0, \text{CharactersEntered}−40\}.$$ Given $I$, the percentage would be, for $I>0$, $x$ plus $I\cdot {100-x\over 10}$ percent. We need a function that tells us if $I>0$ for the following, so let $G=0$ if $I\le 0$ and $G=1$ if $I\ge 1$. Then the formula (probably not the most efficient) is $$G\cdot x + \text{max}\{(0, \text{CharactersEntered}−40\}\cdot {100-x\over 10}.$$