This article mainly introduces the JS floating-point number to keep the two-bit decimal point sample code (rounded) the need for friends can come to the reference, I hope to be helpful to everyone
Code as follows: Var changetwodecimal_f= function (Floatvar) { var f_x = parsefloat (Floatvar); &nbs P if (isNaN (f_x)) { return ' 0.00 '; } var f_x = Math.Round (f_x*100)/100; var s_x = f_x.tostring (); var pos_decimal = S_x.indexof ('. '); if (Pos_decimal < 0) { Pos_decimal = s_x.length & nbsp s_x + = '. '; } while (s_x.length <= Pos_decimal + 2) { s _x + = ' 0 '; } return s_x; } JS provides the rounding function: code as follows: JS rounding function toFixed (), the inside of the parameter is to keep the number of decimal digits. <script language= "JavaScript" > document.write ("<H1>JS reserved two decimal example </h1>< Br> "); var a=2.1512131231231321; &NBSP; document.write ("Original value:" +a+ "<br>"); document.write ("Two decimal point:" +a.tofixed (2) + "<br> Four decimal Places" +a.tofixed (4)); </script>