python cast number to between 0 and 1 1

python cast number to between 0 and 1

NewValue = (((OldValue - OldMin) * (NewMax - NewMin)) / (OldMax - OldMin)) + NewMin

Here is what the above code is Doing:
1. First, we subtract the old minimum from the old value.
2. Then, we multiply the result of that by the new maximum minus the new minimum.
3. Finally, we divide the result of that by the old maximum minus the old minimum.
4. Then, we add the new minimum to the result of that.

Similar Posts