Last active
May 4, 2016 20:56
-
-
Save c01nd01r/74e6d3ff47c3c46ca4546a3e219b4c28 to your computer and use it in GitHub Desktop.
round to precision
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 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