Take the 2-minute tour ×
Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

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?

share|improve this question
    
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. –  FizzledOut Sep 2 '13 at 7:57

2 Answers 2

up vote 2 down vote accepted

$$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$.

share|improve this answer

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$$

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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