首页 > 其他 > 详细

精确到小数点后两位并自动补0

时间:2020-04-22 16:54:24      阅读:73      评论:0      收藏:0      [点我收藏+]

 

 

 

    

export const nub= (num) => {
let f_x=parseFloat(num)
if(isNaN(f_x)){
return false
}
let ff=Math.round(num*100)/100
let s_x=ff.toString()
let pos=s_x.indexOf(".")
if(pos<0){
pos=s_x.length
s_x+="."
}
while(s_x.length<=pos+2){
s_x+="0"
}
return s_x
};

 

精确到小数点后两位并自动补0

原文:https://www.cnblogs.com/zhouyideboke/p/12752751.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!