Files
30-seconds-of-code/snippets/num_to_range.md
Isabelle Viktoria Maciohsek 98b5f67412 Update snippet descriptions
2020-11-02 19:28:27 +02:00

377 B

title, tags
title tags
num_to_range math,beginner

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