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!

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

[+] kaskus emoticons nartzco