1
$\begingroup$

I have a slider than returns percent from 0-1. So I have:

min:0.5
max:3
percent:0.5

I want to retrive what value from range this percent gives (in steps of 0.1). So half from 0.5-3 would be roughly 1.2 (or 1.3 if I round up). How would I calculate this? min can also be positive.

There are 35 steps in increments of 0.1 from 0.5 to 3.0 (0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 1.1, 1.2 etc... 2.9, 3.0) , so 50% for example would be on the half of that.

$\endgroup$
2
  • 1
    $\begingroup$ $\min + (\max - \min)*\text{percent}$ $\endgroup$
    – sudeep5221
    Dec 23, 2019 at 20:09
  • $\begingroup$ This is what I wanted. $\endgroup$
    – Toniq
    Dec 24, 2019 at 0:06

2 Answers 2

1
$\begingroup$

Assuming you want to compute $p$ percent value $v$ between min $m$ and max $M$, where $M > m$ and $0 \le p \le 1$, you compute $$ v = m + p(M-m) = pM + (1-p)m. $$

For your example, $m = 0.5, M = 3$ and $p = 50\% = 0.5$ so we get $$ v = 0.5 + 0.5(3-0.5) = 0.5+1.25=1.75, $$ which is exactly half-way between $M=3$ and $m = 0.5$, as expected.

$\endgroup$
1
  • $\begingroup$ Sorry, I havent expalined well. There are 35 steps in increments of 0.1 from 0.5 to 3.0 (0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 1.1, 1.2 etc... 2.9, 3.0) , so 50% for example would be on the half of that. $\endgroup$
    – Toniq
    Dec 24, 2019 at 0:04
1
$\begingroup$

This sounds like a programming problem. IIUC, you want something like this:

value = percent * (max - min) + min

which in the above case would give $value = 0.5 \times (3 - 0.5) + 0.5 = 1.75$, that is half-way from the min to the max.

$\endgroup$
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .