const thousandth = (num = 123456789, fixed = 0) => { const strNum = num.toFixed(fixed) const [startStr, endStr] = strNum.split('.') let endIdx = startStr.length - 1 let n = 0 const res = [] while(endIdx > -1){ res.unshift(startStr[endIdx]) n++ if(n % 3 === 0 && endIdx !== 0){ res.unshift(',') } endIdx-- } return endStr ? `${res.join('')}.${endStr}` : res.join('') }
标签:const,endStr,res,千分,endIdx,startStr,分隔符 From: https://www.cnblogs.com/zhenjianyu/p/17089259.html