Created
March 28, 2016 23:05
-
-
Save mbreton/8811b39375f9f745a755 to your computer and use it in GitHub Desktop.
Round a decimal number with the given 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 roundDecimal(number, precision) { | |
precision = precision || 2; | |
const tmp = Math.pow(10, precision); | |
return Math.trunc(Math.round(number * tmp) / tmp, precision); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment