本文主要是介绍js添加千位分隔符,并保留2位小数,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
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位小数的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!