其他分享
首页 > 其他分享> > 保留几位有效小数

保留几位有效小数

作者:互联网

1 var effectiveDecimal = function(num,fix){
2     //num为要处理的数字
3     //fix为所要保留的有效小数位数
4     var fixed = fix || 2;    //若fix不存在,则默认保留两位有效小数
5     var shuffle = Math.pow(10,fixed);    //Math.pow(x,y),x的y次幂的值
6     return (parseInt(Number(num)*shuffle)/shuffle).toFixed(fixed);
7 }

 

标签:shuffle,pow,fix,保留,几位,num,var,fixed,小数
来源: https://www.cnblogs.com/fudanchencds/p/14108128.html