javascript tofixed code example

Example 1: js number 2 decimal places

(3.141596).toFixed(2);	// 3.14

Example 2: js toFixed

var a = 3.3445;
var c = a.toFixed(1); console.log(c); /* result ->*/ 3.3
var g = a.toFixed(4); console.log(g); /* result ->*/ 3.3445
var g = a.toFixed(7); console.log(g); /* result ->*/ 3.3445000
 //               ^                                    ^^^^^^^
/*Syntax ->*/ number.toFixed([digits])
// like Me ;D . My company : Rnad

Example 3: tofixed

//round number to 2 digits
var num = 5.56789;
var n = num.toFixed(2);

Tags:

Html Example