Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // 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)
Add Comment
Please, Sign In to add comment