SNos SNos - 6 months ago 27
Swift Question

Swift - `Scale Number in a Range min - max

How can I scale a number to fit in a specified range?
For example if I have:

Input_min = 10.1;
Input_max = 750.0;

Range_min = 0.0;
Range_max = 350.0;

example Input_n = 503.9;


How can I make any number to scale in the Range min and max using swift?

Answer
func convertToRange(number: Double) -> Double {
    return (number - 10.1) / (750.0 - 10.1) * 350
}