vendredi 4 juin 2021

How to normalise a decimal into a number that is a value within a range

How can I normalise a floating point decimal to become a number that is set between a range of max and min value? Is normalise the right word? Following what I want to do.

If I input 0.5 and the range is 0 to 10, then the output should be 5.

If I input 0.799999 and the range is 0 to 10, then the output should be 8.

If I input 0.345 and the range is 0 to 10, then the output should be 3.

If I input 0.555 and the range is 0 to 20, then the output should be 11.

unsigned int Normalise(float value, unsigned int min, unsigned int max) {
    // Return value normalised between min and max
}

I am not super sure if normalise is the right word for this in arithmetic context.

Aucun commentaire:

Enregistrer un commentaire