博客园站长
这是人类成长进步中记录的每一时刻

function formatNum(strNum) {

if (strNum.length <= 3) {

return strNum;

}

if (!/^(\+|-)?(\d+)(\.\d+)?$/.test(strNum)) {

return strNum;

}

var a = RegExp.$1, b = RegExp.$2, c = RegExp.$3;

var re = new RegExp();

re.compile("(\\d)(\\d{3})(,|$)");

while (re.test(b)) {

b = b.replace(re, "$1,$2$3");

}

return a + "" + b + "" + c;

}

posted on 2012-03-31 15:28  dm3344  阅读(3065)  评论(0编辑  收藏  举报