So I am working on a problem for a program I am making...

Say I have two numbers: 10 and 100, than I have a variable. How would i find what percent the variable is between the two numbers?


45 is 50% between 10 and 100

17.5 is 25% between 10 and 100

62.5 is 75% between 10 and 100.

But I need an equation that would work no matter what the 3 numbers were (assuming the number we are solving the percent of is between the two other numbers).

So what percent is 34 in relation to 20 and 300.

Or what percent is 79 in relation to 0 and 85.

  • 1
    $\begingroup$ In what way is 45 50% of the way from 10 to 100? I would have thought the answer would be 55. Your other examples don't make sense to me either. Perhaps you can explain again more precisely what you are looking for. And if you do, I suspect that may help you figure out what the algorithm you are looking for is. $\endgroup$
    – rogerl
    Apr 15, 2014 at 0:35
  • $\begingroup$ I guess your right.. thats just what i was thinking because i figured there is 90 between 10 and 100, half of ninety is 45, so thats half, but it'd be 45 plus 10.. so your right its 55. and also i think that MIGHT have just solved the problem.. lol $\endgroup$ Apr 15, 2014 at 1:02

1 Answer 1


I think I understand what you would like to work out, but I agree with rogerl that you examples may be wrong. I think what you've done (e.g. in your first example) is $(100-10)\times \frac{1}{2}=45$ and said therefore 45 is 50% between 10 and 100 which is isn't since $(100-10)\times\frac{1}{2}+10=55$ is.

To your question, how can we work this out generally. You may be able to see from what I did above but given some number $x$ in the range $a$ to $b$ we can work out what percentage of $x$ that is in between $a$ and $b$ with: $$ \text{Percentage}(x,a,b)=\frac{x-a}{b-a} $$

For one of your examples you have $x=34$ and $a=20$ and $b=300$ which gives: $$ \frac{34-20}{300-20}=\frac{1}{20} $$ which we can check by the more intuitive way of thinking about it, just remembering to add the $20$ which is where I think you may have went wrong: $$\frac{1}{20}\times (300-20)+20=34$$

  • $\begingroup$ Yep! thats it! I noticed after @rogerl commented that my concept was flawed... I was finding the middle between the difference of the two bounding numbers, and that was it. I needed to take the lower boundary into mind. but also id does need to be the ABSOLUTE of x-a Percentage(x,a,b) = |x-a|/b-a $\endgroup$ Apr 15, 2014 at 1:08
  • $\begingroup$ It depends on how you want to define it. I don't think so, since for example if you let $x=10$ with $a=20$ and $b=300$ doing it without the absolute value gives a value of $-\frac{1}{28}$ which if we reverse the operation to find $x$ like we did in the question: $-\frac{1}{28}\times(300-20)+20=10$ whereas if we took the absolute value it would be $\frac{1}{28}(300-20)+20=30$ which is indeed 1/28th the way between 30 and 300 but it tells us nothing about the original value of $x$ we had that was $x=10$. So it depends on how you want to define percentages for $x$ outside the range $[a,b]$. $\endgroup$
    – Jay
    Apr 15, 2014 at 1:16

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