js添加和去除千分号
利用js的replace方法和正则表达式实现
1.先给“582123456.23”添加千分号
var testStr="582123456.23";
var reStr = testStr.replace(/,/g, "");
alert(reStr); //582,123,456.23
2.在数字比较的时候通常要去除已经存在的千分号
var reStr="582,123,456.23"
var regexStr = /(\d{1,3})(?=(\d{3})+(?:$|\.))/g;
var resultStr = reStr.replace(re, "$1,");
alert(resultStr );//582123456.23