<script language="javascript"> document.write("<h1>JS保留两位小数例子</h1><br>"); var a=2.1512131231231321; document.write("原来的值:"+a+"<br>"); document.write("两位小数点:"+a.toFixed(2)+"<br>四位小数点"+a.toFixed(4)); </script>
要是提示错误 找不到该方法 就先进行转换
var a=ParseFloat(a).toFixed(2).
转载于:https://www.cnblogs.com/licuihua/p/8793937.html