2
$\begingroup$

Here is a really dumb question, but I cannot find answers on Google for some reason or other. All the answers seem to be buried under mounds of percent difference formulas (which is not what I am asking).

I am trying to generate a value between two variables based on a percentage.

$$\begin{align*} 0\% &= X \qquad \text{(the minimum value)}\\\\ 50\% &= \frac{X + Y}{2}\\\\ 100\% &= Y\qquad \text{(the maximum value)} \end{align*}$$

What would the formula be?

$\endgroup$
  • $\begingroup$ Readers, it might be useful to know that this is essentially the lerp() function, which stands for linear interpolation. I figured this out after a little under a month that I posted. $\endgroup$ – person27 Sep 2 '13 at 7:57
2
$\begingroup$

$$X+(\text{percent here})\cdot(Y-X)$$ So for example,

$X+(25\%)\cdot(Y-X)$ is $25$ percent of the way to $Y$, from $X$.

$\endgroup$
2
$\begingroup$

The formula for "$t$ percent", where $t$ is any number between $0$ and $100$, is $$\left(1-\frac{t}{100}\right)X+\left(\frac{t}{100}\right)Y$$

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.