Skip to content

Instantly share code, notes, and snippets.

@ology
Created November 23, 2025 17:43
Show Gist options
  • Select an option

  • Save ology/fcc966ef210b85387ef9fdb0c91fc675 to your computer and use it in GitHub Desktop.

Select an option

Save ology/fcc966ef210b85387ef9fdb0c91fc675 to your computer and use it in GitHub Desktop.
scaling to integer range in python by hand πŸ™„
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