Skip to content

Instantly share code, notes, and snippets.

@c01nd01r
Last active May 4, 2016 20:56
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 c01nd01r/74e6d3ff47c3c46ca4546a3e219b4c28 to your computer and use it in GitHub Desktop.
Save c01nd01r/74e6d3ff47c3c46ca4546a3e219b4c28 to your computer and use it in GitHub Desktop.
round to precision
function round(number, prec) {
prec = prec || 0;
return Math.round(number * Math.pow(10, prec)) / Math.pow(10, prec);
}
//round(4.9156, 3);
//4.916
//round(4.9155, 3);
//4.916
//round(4.9154, 3);
//4.915
//round(4.9154);
//5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment