Answer the question
In order to leave comments, you need to log in
How to get a value by percentage in a range of two numbers?
For example:
A value of 10% in the range between 0.0 and 20.0 would be 2.0
A value of 50% in the range between -5.0 and 5.0 would be 0
The difficulty is that this is a vector calculation, and - on - does not give here +
The range can be, for example, ( -5.0, -10.0), (5.0, 10.0), (-5.0, 10.0), in general, go both up and down.
This task arose in the development of the game. Example:
(float StartValue, float EndValue, float Percent) {
const float OnePercent = (EndValue - StartValue) / 100.0f;
return StartValue + OnePercent * Percent;
}
Answer the question
In order to leave comments, you need to log in
Read about interpolation. Your example is quite correct both with negative numbers and with the reverse order. Think better.
UPD : moreover, this formula is valid for vectors of arbitrary dimension, and for angles, and for many other quantities.
Формула универсальная для любых чисел, шаг в сторону endvalue от startvalue
Чем не устраивает формула , покажите на примере конкретных вычислений.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question