精确到小数点后两位并自动补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
};

 

posted @ 2020-04-22 16:07  又回到了起点  阅读(689)  评论(0编辑  收藏  举报