function semicolon_Add(num){ num = num.replace(/,/g,""); if (num != ""){ var re = /^\d+(\.\d+)?$/; if(re.test(num)){ var parts = num.toString().split("."); parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ","); if(parts.length==1){ num =parts[0]+'.00'; }else if(parts[1].length>=2){ num =parts[0]+"."+parts[1].substring(0,2); }else { num = parts[0]+"."+parts[1]+'0' } } } return num; }
标签:四舍五入,parts,replace,num,千分号,补零 From: https://www.cnblogs.com/jervy/p/17537257.html