Files
30-seconds-of-code/snippets/num_to_range.md
Isabelle Viktoria Maciohsek cbc78ee450 Bake dates into snippets
2021-06-13 19:38:10 +03:00

21 lines
456 B
Markdown

---
title: num_to_range
tags: math,beginner
firstSeen: 2020-10-04T12:43:57+03:00
lastUpdated: 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`.
```py
def num_to_range(num, inMin, inMax, outMin, outMax):
return outMin + (float(num - inMin) / float(inMax - inMin) * (outMax
- outMin))
```
```py
num_to_range(5, 0, 10, 0, 100) # 50.0
```