# How to calculate the percentage of a value contemplating negative numbers?

min = 0
max = 100
v = 50


Given those values, I can calculate the percentage of "completion" for v within the range [min,max] like this:

(100.0 / max) * v


And I get 50% - the desired value.

As you can see, I don't even use the min variable. So I have problems when this happens:

min = -100
max = 100
v = -50


I would expect the above values to produce 25%. But clearly, my earlier formula can't do that.

What can I do to calculate such values then? What changes are necessary?

-

The length of the interval $[min,max]$ is $$max-min=100-(-100)=100+100=200$$
The length of the interval $[min,v]$ is $$v-min=(-50)-(-100)=-50+100=50$$
So the completion for $v$ is $$\frac{50}{200}=25\%$$
Note that in your first case $min$ was $0$ so $\frac{v-min}{max-min}\cdot100$ equaled $\frac{v}{max}\cdot100=\frac{100}{max}\cdot v$ so your formula worked in this case because $min$ equaled $0$ and did not work in the second case because $min$ did not equal $0$ .