本篇文章主要是对js将数值转换为3位逗号分隔的示例代码进行了介绍,需要的朋友可以过来参考下,希望对大家有所帮助
实例代码: 代码如下: 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; }