Skip to content

Instantly share code, notes, and snippets.

@aradnom
Created February 20, 2014 00:47
Show Gist options
  • Save aradnom/9104740 to your computer and use it in GitHub Desktop.
Save aradnom/9104740 to your computer and use it in GitHub Desktop.
Round number to nearest <n> (5, 10, 50, etc.)
// Round value to nearest <n>
// multiplier allows values to be multiplied and stay rounded to nearest <n>
// (i.e. 1732 * 2 => nearest 50)
function RoundTo ( value, to, multiplier ) {
multiplier = multiplier || 1;
return Math.round( ( parseInt( value ) * multiplier ) / to ) * to;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment