最终效果

.num = formatNumber_thousands(1231131313);

得到
1,231,131,313

函数封装

// 数字格式化——千分位分隔符
function formatNumber_thousands(num) {
if (isNaN(num)) {
throw new TypeError("参数不是一个数字");
}

return ("" + num).replace(/(\d{1,3})(?=(\d{3})+(?:$|\.))/g, "$1,");
}