Taking to values and turning them into precentages

16 Views Asked by At

I want to basicly take a range of two values so for example 20-40 and then taking a value in between for say 30 and somehow mathematicly make it say that it is 50% between the values. This should work for any range so 24-44 if we take 34 then its 50% or if we take 24 its 0% or if we take 44 we take 100%.. (This is for programming)..

1

There are 1 best solutions below

0
On BEST ANSWER

Say if you choose the boundaries as $a$ and $b$ and the number you choose is $x$, then your answer would be $\dfrac{x-a}{b-a} \cdot 100$

For example, let's take $a = 20$ and $b=40$ and say, $x = 30$. Then your percentage is $\dfrac{30-20}{40-20} \cdot 100 = 50$