栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

JavaScript数字转Words

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

JavaScript数字转Words

当前导零数字时,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];    }


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/405040.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号