function milliFormat(s){//添加千位符
if(/[^0-9\.]/.test(s)) return "invalid value";
s=s.replace(/^(\d*)$/,"$1.");
s=(s+"00").replace(/(\d*\.\d\d)\d*/,"$1");
s=s.replace(".",",");
var re=/(\d)(\d{3},)/;
while(re.test(s)){
s=s.replace(re,"$1,$2");
}
s=s.replace(/,(\d\d)$/,".$1");
return s.replace(/^\./,"0.")
}
js添加千位分隔符,并保留2位小数
最新推荐文章于 2024-01-30 14:52:32 发布