[Math] Calculate percentage given value, minim and maximum

algebra-precalculus

It's my first time on Math.stack; be gentle.

I have slider with a range between -1 and 1.
If my slider is at 0 I'd expect it to be at 0%
If it were at either -1 or 1 I'd expect it to be 100%
However it must take into account those won't always be the max & min

When I've got a minimum value of -0.1896362 and maximum value of 0.1383057 I get a bit confused

This is what I've got so far (This is wrong):

percentage = ((slider-minimum)/(maximum-minimum)) *100

I've read this post which is similar to my problem, but the negative numbers are messing things up.

Best Answer

Alright, so let's take $u$ to be the upper bound. Lets make $l$ the lower bound. When you go to the right, the percentage of the area swept from x=0 to some $x$ the right is:

$$\frac{x}{u}\times 100\%$$

Similarly, on the left you'll just use your lower bound. You don't even need absolute value because the negatives will cancel:

$$\frac{x}{l}\times 100\%$$

Let me know if that's what you meant.