Scaling an integer?

Dec 22, 2016 at 12:51pm
Is there a function that allows you to scale an integer to another one?
For example:
1
2
3
4
5
6
7
int a; //int with a value between 1-100;
int b; //int with a value between 100-1000;
int c = scale(a,1,100,b,100,1000);
//scale a up to b
//the bigger the value of a, the bigger the returned value, to a maximum of 1000
//Ex: if a is 100, returns 1000
//the returned value is beween 100-1000 

Sorry for the messy explanation.
Last edited on Dec 22, 2016 at 12:52pm
Dec 22, 2016 at 12:58pm
You can write that easily, can't you?
Dec 22, 2016 at 1:29pm
Sorry, you're right. My brain was foggy.
Here's the code if anyone needs it:
1
2
3
4
5
6
//Scales a float to an interval
float scale(float A, float A1, float A2, float Min, float Max)
{
    long double percentage = (A-A1)/(A1-A2);
    return (percentage) * (Min-Max)+Min;
}
Topic archived. No new replies allowed.