Created
February 20, 2014 00:47
-
-
Save aradnom/9104740 to your computer and use it in GitHub Desktop.
Round number to nearest <n> (5, 10, 50, etc.)
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
// 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