Skip to content

Instantly share code, notes, and snippets.

@sebassdc
Created June 9, 2016 04:29
Show Gist options
  • Save sebassdc/7f7e3a87bf7e400e33b970adb30d05e8 to your computer and use it in GitHub Desktop.
Save sebassdc/7f7e3a87bf7e400e33b970adb30d05e8 to your computer and use it in GitHub Desktop.
/*
-number: input number
-min: Minimun number
-max: Maximun number
given a number and a minimun a maximun
calculate the equivalent percentage
*/
float valtope(float number, float min, float max){
float res = ((number - min) / (max - min)) * 100;
return res;
}
/*
-percent: input percentage
-min: Minimun number
-max: Maximun number
given a percentage and a minimun a maximun
calculate the equivalent number
*/
float petoval(float percent, float min, float max){
float res = (percent/100.0) * (max - min) + min;
return res;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment