转载:
http://www.cnblogs.com/446557021/archive/2011/10/13/2211047.html
<script language="javascript">var a=2.1512131231231321; document.write("两位小数点:"+a.toFixed(2)+"<br>四位小数点"+a.toFixed(4)); </script>