Posted in Javascript onFebruary 19, 2014
function formatNum(num) { if(!/^(\+|-)?(\d+)(\.\d+)?$/.test(num)){alert("wrong!"); return num;} var a = RegExp.$1, b = RegExp.$2, c = RegExp.$3; var re = new RegExp().compile("(\\d)(\\d{3})(,|$)"); while(re.test(b)) b = b.replace(re, "$1,$2$3"); return a +""+ b +""+ c; }
JS将数字转换成三位逗号分隔的样式(示例代码)
声明:登载此文出于传递更多信息之目的,并不意味着赞同其观点或证实其描述。
Reply on: @reply_date@
@reply_contents@