-
-
Save ology/fcc966ef210b85387ef9fdb0c91fc675 to your computer and use it in GitHub Desktop.
scaling to integer range in python by hand π
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def scale_number(value, original_min, original_max, target_min, target_max): | |
| if original_max == original_min: | |
| return target_min | |
| scaled_value = ((value - original_min) * (target_max - target_min)) / (original_max - original_min) + target_min | |
| return round(scaled_value) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment