当前导零数字时,Javascript会将3个数字的组解析为八进制数字。当三位数字的组全部为零时,无论基数是八进制还是十进制,结果都是相同的。
但是,当您给Javascript‘009’(或‘008’)时,这是一个无效的八进制数字,因此您会得到零。
如果您经历了从190,000,001到190,000,010的整个数字集,您将看到Javascript跳过’…,008’和’…,009’,但是为’…,010’发出‘8’。那就是“尤里卡!”
时刻。
更改:
for (j = 0; j < finlOutPut.length; j++) { finlOutPut[j] = triConvert(parseInt(finlOutPut[j]));}至
for (j = 0; j < finlOutPut.length; j++) { finlOutPut[j] = triConvert(parseInt(finlOutPut[j],10));}代码还在每个非零组之后继续添加逗号,因此我玩了一下,找到了添加逗号的正确位置。
旧:
for (b = finlOutPut.length - 1; b >= 0; b--) { if (finlOutPut[b] != "dontAddBigSufix") { finlOutPut[b] = finlOutPut[b] + bigNumArry[bigScalCntr] + ' , '; bigScalCntr++; } else { //replace the string at finlOP[b] from "dontAddBigSufix" to empty String. finlOutPut[b] = ' '; bigScalCntr++; //advance the counter }} //convert The output Arry to , more printable string for(n = 0; n<finlOutPut.length; n++){ output +=finlOutPut[n]; }新:
for (b = finlOutPut.length - 1; b >= 0; b--) { if (finlOutPut[b] != "dontAddBigSufix") { finlOutPut[b] = finlOutPut[b] + bigNumArry[bigScalCntr]; // <<< bigScalCntr++; } else { //replace the string at finlOP[b] from "dontAddBigSufix" to empty String. finlOutPut[b] = ' '; bigScalCntr++; //advance the counter }} //convert The output Arry to , more printable string var nonzero = false; // <<< for(n = 0; n<finlOutPut.length; n++){ if (finlOutPut[n] != ' ') { // <<< if (nonzero) output += ' , '; // <<< nonzero = true; // <<< } // <<< output +=finlOutPut[n]; }


