Last active
August 10, 2020 15:58
-
-
Save semihkeskindev/f276308b27bdb150d85f1226c6e00fa8 to your computer and use it in GitHub Desktop.
Javascript function for Round to any decimal place
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 roundNumber(num, precision = 0) { | |
let decimalPlace = Math.pow(10, precision); | |
return Math.round((num + Number.EPSILON) * decimalPlace) / decimalPlace; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If you wonder why i use "Number.EPSILON", thats why below:
https://stackoverflow.com/a/11832950/10956918