There are many ways to retain two decimal places in tabular numbers. The following article will introduce how to use js to implement them in detail: multiple methods for formatting data in JavaScript to retain two decimal places
Best method:
Keep the two. It seems like this is the case.
The Code is as follows:
Var a = 9.39393;
Alert (a. toFixed (2 ));
Note:
Alibaba (Number. toFixed (9.39393 ));
9.39 is returned.
However, only ie5.5 or later versions are supported.
Other methods:
Function roundFun (numberRound, roundDigit) // rounding, the number of reserved digits is roundDigit {if (numberRound> = 0) {var tempNumber = parseInt (numberRound * Math. pow (10, roundDigit) + 0.5)/Math. pow (10, roundDigit); return tempNumber;} else {numberRound1 =-numberRound var tempNumber = parseInt (numberRound1 * Math. pow (10, roundDigit) + 0.5)/Math. pow (10, roundDigit); return-tempNumber ;}}
Method 2:
《script》 tmp = "1234567.57232" result = tmp.substr(0,tmp.indexOf(".")+3); alert(result); 《script》
Method 3:
The Code is as follows:
Var a = 3.1415926;
A = a. toFixed (2); // retain 2 bits, but the result is of the String type.
A = parseFloat (a); // convert the result to float
// Use the following steps:
A = parseFloat (a. toFixed (2 ));