Last active
April 29, 2021 06:56
-
-
Save oskarnrk/d5e21dcf448d9aa540a0c42fb968c93f to your computer and use it in GitHub Desktop.
Round a number by decimal places (default: 1)
This file contains hidden or 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
const roundDecimalPlaces = (num, decimalPlaces) => { | |
// default: 1 decimal places | |
decimalPlaces = !decimalPlaces ? 1 : decimalPlaces; | |
return Math.round(num * 10 * decimalPlaces) / (10 * decimalPlaces); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment