Percentage help for my slider program.

66 Views Asked by At

I'm trying to create a program which allows the user to enter in any number of values, where each value can be any number. For example, the user may choose to enter the following 4 values:

-478.93
485.44
569.48
593.82

What formula do I need to use to get the slider in the program to show -478.93 when the slider is at the 0% position and 593.82 when the slider is at the 100% position? The slider should show the correct value at all other percentages.

For example, when at the 50% position, it should show 292.4525, which is the average of the values entered in by the user:

292.4525 = ( -478.93 + 485.44 + 569.48 + 593.82 ) / 4
1

There are 1 best solutions below

0
On

Let $a$ be the minimal value (here $a=-478.93$), $c$ the maximal value (here $c=593.82$) and $b$ the average (here $b=292.4525$). Then let the percentage $x$ ($0\le x\le 100$) correspond to

$$ f(x)=\begin{cases}a+\frac x{50}(b-a)&\text{if }0\le x\le 50\\ 2b-c+\frac x{50}(c-b)&\text{if }50\le x\le 100\end{cases}$$ (This corresponds to CAGT's suggestion of two slopes).