题解 | #分隔符#
分隔符
https://www.nowcoder.com/practice/e5696992841841a8ab9d026324e4bb77
function _comma(number) {
// 补全代码
let len = parseInt((number + '').length / 3);
let numYu = parseInt(number % (Math.pow(1000, len)));
let num1 = parseInt(number / (Math.pow(1000, len)));
if (num1 == 0) {
len = len - 1;
num1 = parseInt(number / (Math.pow(1000, len)));
numYu = parseInt(number % (Math.pow(1000, len)));
}
let resultStr = '' + num1;
console.log(num1);
console.log(numYu);
console.log("len" + len);
for (let i = len - 1; i >= 0; i--) {
console.log(i);
console.log(parseInt(numYu / (Math.pow(1000, i))));
resultStr += ',' + parseInt(numYu / (Math.pow(1000, i)));
numYu = numYu % (Math.pow(1000, i));
};
console.log(resultStr);
return resultStr;
}