JS Number Format with Decimal

Here we will make number formatting in javascript, javascript has function math.round() to round up number. But how if we want the format to be has 2 decimal point?
Example we has number 12.3987 and we want after the format the result will be 12.39.

var number=12.3987;

Math.round(number) // result 12
Math.round(number*100)/100 // result 12.39
Math.round(number*1000)/1000 // result 12.398

Simple!

Posting komentar anda