I am pretty sure that is not quite correct e.g. say
- InputMin,InputMax = 4,20
- ScaledMin,ScaledMax = 4,20
- i.e. OutputValue should always equal InputRaw
- So for InputRaw = 12 (half-scale):
- (12 - 4) * (20 - 4) / ((20 - 4) + 4) = OutputValue
- (8) * (16) / ((16) + 4) = OutputValue
- (8 * 16) / (20) = OutputValue
- (128) / (20) = OutputValue
- (6.4) = OutputValue, which is not equal to the InputRaw (12)
That said, it will give correct results if [Scaled Min] is zero, and believable results of [Scaled Min] is a small fraction (1% or so) of [Scaled Max].
The correct formula is
(Input Raw - Input Min) * (Scaled Max - Scaled Min) / (Input Max - Input Min) + Scaled Min = Output
with "conventional" precedence rules (mult and div before adding; left-to-right or right-to-left for equal operator precedence), or
((Input Raw - Input Min) * (Scaled Max - Scaled Min) / (Input Max - Input Min)) + Scaled Min = Output
to eliminate more operator precedence rules as a possible issue other than parenthetical statements evaluated first and inside to outside.
I used to be amazed at the frequency at which scaling questions comes up on this forum. But then I watched a quiz competition on a twitch channel where one adult thought named "Van Golf" painted the Mona Lisa, another said the product of 19 and 11 was 201, and a third said 209 but needed the entire thirty seconds to get there.