猿问

​编写函数,例如“123”转换为"壹佰贰拾叁"

编写函数,将一个数字字符串全部转换为中文大写(带单位),例如“123”转换为"壹佰贰拾叁"

用JS知识

精慕门2092353
浏览 2277回答 0
0回答

慕田峪6141110

NJMDPZJWJUQEEXNDTIMSGJDGTJSCCWJWEGFOIEBXZCERVEYFVVBSLZZMPTDABVYFZJHGCYZPBLRYOHGJCMFJFFZEOENJPIAAWNGLADJIVGTZMJWMLOBFRLJPMHWTFEEFDZGMBBUGSCOOLRBGPYBBRAPCMJDGKZFIQMWJCKTGMSOUXHRVGPSEUVUSYWFBENKWWTTFWFAUJWSVTJJCNUNAQDADRVLBXNGZIJYGVEUEBTWFFLFZZMAQQZGDSVSYOXQTCBVOZPOOUFYMHBURHFFIRENTRBNNBBLUDNSGLORYKAJWQPJDQMJGEXXETMISIRYFLPMBCOFOFFDSZFROOROOPPOVRAENAQNTFCDWTWAWWGTLUUKLOAFYIGJIYSYWCGJQTTMLPYPCPFHNWVUSYPLCILTKJMFWTMNWQGYUJEEOKBMJZHWSGDQJOBLUJSIPLVUBOKAXQCUQIXNUEBHNJZVYFGZGSAZVHNAJBADXZRBFFEUKQDAWPOOSZYLBPWMVYQRUAHATNBHTXNRRDATAMBKBUTJALCCUEDRLUESLJFXGCCSFRJCAOQHJMQDPGSZMNZOVEBQDTKWXKJQHRGYOBRSDSFPCIIBWCKKTZWTGCCTGHQZJTTNHXZVUTCVFPJAJYONQFPFTDFIMVDTNKUJNQMYUBDAQGWFVRVRHXZCZOSORILBYGRAWZWSIEBQLPZJLACMPOJSBLOYHJZJMOQNEAJYIZNJTJSVYTWMCZUQSVLAPFIZJHQMCFBCSBLURNVTJYOYGCFBDYVYUYTJMCHDMORBKNJTQZPEHESCFPSWUJZDRUKADTJCLAJTJSHDMWIZBLBKTJYISRFHQUKAWLPFMVVBRRTDQGQAGKANZVVUKHKNTMCKBUQXD

奔跑的虫子

<!doctype html> <html>  <head>     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">      <script>     function toChinaNum(str){             var num=parseInt(str);    //    将字符串转换为整数                          if(!isNaN(num)){        //    如果转换正确 则下一步 否则输出错误提示                                      //    [当字符串非数字类字符串时 为NaN 不能转换]                 var re_ch_num="";                 var ch_num;                 for(var i=1;i<=str.length;i++){                     c_num=num%10;            //    求个位数的数字 以便转换为汉字                     num=parseInt(num/10);    //    每求出一个个位数 则除以十 将上位数转换为个位数 做下一个判断                     switch(i){                                             //    根据i得出除以了多少个10 加上汉字位数                         case 1:                             re_ch_num+="个";    //    可以不写                             break;                         case 2:                             re_ch_num+="拾";                             break;                         case 3:                             re_ch_num+="百";    //偷个懒只写几个                             break;                         default :                             break;                     }                     switch(c_num){                                     //    一个个的转换为汉字                         case 1:                             re_ch_num+="壹";                             break;                         case 2:                             re_ch_num+="贰";                             break;                         case 3:                             re_ch_num+="叁";    //偷懒                             break;                         default :                     }                                                          //    因为是从个位数向高位判读 所以字符串是反的 需要将字符串反转                     ch_num=re_ch_num.split("").reverse().join("");                 }                 return     ch_num;             }else{                 error.innerHTML="转换错误 请仔细查看是否为整数字符串";             }         }     </script>   </head>    <body>     <div id="toChina"></div><br>     <div style="background:red" id="error"></div>     <script>         var change=document.getElementById("toChina");         var error=document.getElementById("error");         var oldnum="123";         change.innerHTML=oldnum+" -- > 转换为中文为  : "+toChinaNum(oldnum);     </script> </body> </html> /*********** 如果输入的字符串为 "12m" 这样的尾数为字符混合字符串会有点小问题你可以自己改一下 祝愉快 ************/

XAGT

用equals()比较函数就行了,你先输入,比较结果为true就输出

牛奶老哥哥

您这是在发布任务呢
随时随地看视频慕课网APP

相关分类

JavaScript
我要回答