码迷,mamicode.com
首页 > Web开发 > 详细

JS保留两位小数 四舍五入函数

时间:2017-09-14 13:22:12      阅读:140      评论:0      收藏:0      [点我收藏+]

标签:pre   asc   例子   style   rip   fixed   class   tofixed   code   

js 四舍五入函数 toFixed(),里面的参数 就是保留小数的位数。

1 <script language="javascript"> 
2 document.write("<h1>JS保留两位小数例子</h1><br>");  
3    var a=2.1512131231231321;  
4    document.write("原来的值:"+a+"<br>");  
5    document.write("两位小数点:"+a.toFixed(2)+"<br>四位小数点"+a.toFixed(4));  
6 </script> 

 

by 小鬼PSer 2017-09-14 11:45:36

JS保留两位小数 四舍五入函数

标签:pre   asc   例子   style   rip   fixed   class   tofixed   code   

原文地址:http://www.cnblogs.com/php-qiuwei/p/7519876.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!