function thousandBitSeparator(num) { num=num.toFixed(2); return num && num .toString() .replace(/(\d)(?=(\d{3})+\.)/g, function($1,$2) { return $2 + ","; }); }console.log(thousandBitSeparator(-111111111111110.0000001));
时间: 2024-10-13 15:56:11
function thousandBitSeparator(num) { num=num.toFixed(2); return num && num .toString() .replace(/(\d)(?=(\d{3})+\.)/g, function($1,$2) { return $2 + ","; }); }console.log(thousandBitSeparator(-111111111111110.0000001));