Search code examples
normalizationnormalize

normalizing number between 2 ranges


I know this may be a fairly basic thing but I'm having a lot of difficulty with it. I have some numbers which could be anywhere between 0.449999988079 and 10.0. What I would like to do is normalise these numbers so they are between 0.1 and 0.5. Could anyone help with achieving this please.

Thanks


Solution

  • function normalize(num, fromMin, fromMax, toMin, toMax)
    {
        return toMin + (num - fromMin)/(fromMax - fromMin) * (toMax - toMin)
    }