Skip to content

Home

Map number to range

Maps a number from one range to another range.

def num_to_range(num, inMin, inMax, outMin, outMax):
  return outMin + (float(num - inMin) / float(inMax - inMin) * (outMax
                  - outMin))

num_to_range(5, 0, 10, 0, 100) # 50.0

More like this

Start typing a keyphrase to see matching snippets.