Skip to content

Instantly share code, notes, and snippets.

@squalvj
Created January 8, 2019 14:55
Show Gist options
  • Save squalvj/a9462afb5291c7755391b2906edb67fc to your computer and use it in GitHub Desktop.
Save squalvj/a9462afb5291c7755391b2906edb67fc to your computer and use it in GitHub Desktop.
Algorithm calculate third number based on min max and convert them to percent
// basic
var max = 250
var min = 50
var input = 65
var percent = ((input - min) * 100) / (max - min)
// a little longer
var range = max - min
var correctedStartValue = input - min
var percentage = (correctedStartValue * 100) / range
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment