Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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!

share|cite|improve this question
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
up vote 0 down vote accepted

Could you just take the maximum of $0$ and $(\text{CharactersEntered}−40)\cdot10$ (percent)?

Added from the comment:

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

share|cite|improve this answer
Thanks! One last question... what if I wanted the threshold to be another value like 60% or 75% (instead of the 80%). I thought I just needed to change the "x 10" at the end of your equation, but it's not working. What value would I use to multiply by for these other percentages? – bmccleary Feb 17 '12 at 23:54
@bmccleary Sorry, my last comment was a bit off. I expanded the answer to address your question. – David Mitra Feb 18 '12 at 0:39
Got it! Thanks again. – bmccleary Feb 18 '12 at 0:42

Your Answer


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.