Skip to content

Instantly share code, notes, and snippets.

@doughamlin
Created March 4, 2013 18:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save doughamlin/5084154 to your computer and use it in GitHub Desktop.
Save doughamlin/5084154 to your computer and use it in GitHub Desktop.
A better Javascript rounding function: Round X to the Nth digit
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