Files
30-seconds-of-code/snippets/python/s/num-to-range.md
2023-05-07 16:07:29 +03:00

471 B

title, type, language, tags, cover, dateModified
title type language tags cover dateModified
Map number to range snippet python
math
round-leaves 2021-04-05T18:25:46+03:00

Maps a number from one range to another range.

  • Return num mapped between outMin-outMax from inMin-inMax.
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