1 /** 2 * 数字转为千分位字符 3 * @param {Number} num 4 * @param {Number} point 保留几位小数,默认2位 5 */ 6 function parseToThousandth(num, point = 2) { 7 let [sInt, sFloat] = (Number.isInteger(num) ? `${num}` : num.toFixed(point)).split('.'); 8 sInt = sInt.replace(/\d(?=(\d{3})+$)/g, '$&,'); 9 return sFloat ? `${sInt}.${sFloat}` : `${sInt}`;10 }11 12 parseToThousandth(1234567); // '1,234,567'