Created
March 4, 2013 18:02
-
-
Save doughamlin/5084154 to your computer and use it in GitHub Desktop.
A better Javascript rounding function: Round X to the Nth digit
This file contains 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
function roundTo(x,n) { | |
if(!n) { n = 2; } | |
var result = x * Math.pow(10,n); | |
var result = Math.round(result); | |
var result = result / Math.pow(10,n); | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment