CristalT
1/18/2019 - 4:27 PM

Two ways to round a number at 2 decimals

// 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)