日期:2014-05-16 浏览次数:20365 次
利用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
?
转自http://www.cnblogs.com/loveok-56/archive/2011/08/15/2139499.html