Guest User

Untitled

a guest
Jan 19th, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.39 KB | None | 0 0
  1. // Two Ways To round a number at 2 decimals
  2. const number = 19.5862365
  3.  
  4. // Way one
  5. let result = Math.round(number * 100) / 100
  6. console.log(result)
  7.  
  8. // Way two
  9. result = parseFloat(number.toFixed(2)) // parseFloat() to keep number type
  10. console.log(result)
  11.  
  12. // BONUS !!
  13. result = new Intl.NumberFormat('en', {
  14. minimumFractionDigits: 2,
  15. maximumFractionDigits: 2
  16. }).format(number)
  17. console.log(result)
Add Comment
Please, Sign In to add comment