带小数点的
var a = 8462948.2453;
console.log(a.toLocaleString()) //8,462,948.245
不带小数点的
num.toString().replace(/(\d)(?=(\d{3})+$)/g,'$1,')
满足两者情况的
function numFormat(num) {
var c = (num.toString().indexOf ('.') !== -1) ? num.toLocaleString() : num.toString().replace(/(\d)(?=(\d{3})+$)/g, '$1,');
return c;
}