js 格式化数字,数字每隔三位加个逗号
function formattedNumber(num) {
var num = (num || 0).toString();
var result = '';
while (num.length > 3) {
result = ',' + num.slice(-3) + result;
num = num.slice(0, num.length - 3);
}
if (num) { result = num + result; }
return result;
}