1 /* * 2 * Convert the number to thousandth character 3 * @param {Number} num 4 * @param {Number} point retain several decimal places, default 2 digits 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'