Find percentage value between 2 numbers

587 Views Asked by At

Let's say I want to move a shape with coordinates.

The end position is: -500 pixels. The start position is: 500 pixels.

Using a slider with a range of 1-100, I want to move the shape between the start and end position using percentage. When this percent value changes, I want to move the shape. 100% would place the shape at the end position, 0% would place the shape at the start position. Any percentage between would set the pixel value accordingly.

Letters below are variables.

A: -500

B: 500

C: Percentage value between (1-100).

D: (ANSWER)

I need a new value (D) to be the percentage value (C) between (A) & (B).

So if (C) was 50 - (D) would be value 0.

50% between A and B is 0.
2

There are 2 best solutions below

6
On BEST ANSWER

I think you are looking for $$ D = A + (B-A)\cdot \frac{C}{100} $$ or, with your particular $A$ and $B$ inserted, $$ D = 10\cdot C - 500 $$

2
On

Given two numbers $\alpha $ and $\beta $, a percentage change of $\gamma $ gives the position as $\delta =\alpha +\frac {\beta-\alpha}{100}\gamma $. Try using this result with $\alpha=-500$ and $\beta=500$. Hope it helps.