Created
January 18, 2019 16:27
-
-
Save CristalT/5b336cba180e76200bab0a53196b560e to your computer and use it in GitHub Desktop.
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
// Two Ways To round a number at 2 decimals | |
const number = 19.5862365 | |
// Way one | |
let result = Math.round(number * 100) / 100 | |
console.log(result) | |
// Way two | |
result = parseFloat(number.toFixed(2)) // parseFloat() to keep number type | |
console.log(result) | |
// BONUS !! | |
result = new Intl.NumberFormat('en', { | |
minimumFractionDigits: 2, | |
maximumFractionDigits: 2 | |
}).format(number) | |
console.log(result) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment