自己的解决方案是整数部分4位一分组,每组对应一个大单位,组内对应小单位
//yuyong 5-23 var chineseMoney=""; var numMoney="01.23"; var chinese_number=["零","壹","贰","叁","肆","伍","陆","柒","捌","玖"]; var chinese_zheng_qian1=["","万","亿"]; var chinese_zheng_qian2=["","拾","佰","仟"]; var chinese_ling_qian=["角","分"]; var money_Reg=/^\d{1,12}(\.\d{1,2})?$/; if(!money_Reg.test(numMoney)){ alert("数字格式不对!"); }else{ var zheng_qian=Number(numMoney.split("\.")[0])+""; var ling_qian=numMoney.split("\.")[1]; var length=parseInt(zheng_qian.length/4)+(zheng_qian.length%4!=0?1:0); for(var x=1;x<=length;x++){ var start=(x-1)*4+1; var temp=""; for(var y=0;y<=3;y++){ //每四位一组中从低到高 单位为 ""->拾->佰->仟 var a=zheng_qian.charAt(zheng_qian.length-start); if(a=='0'){ if(temp!=""){ //4位一组中两个连续的零 ,中文中只读一个零 if(zheng_qian.charAt(zheng_qian.length-start+1)!='0') temp=chinese_number[a]+temp; } }else temp=chinese_number[a]+chinese_zheng_qian2[y]+temp; if(start==zheng_qian.length) break; else start++; } if(temp!='') chineseMoney=temp+chinese_zheng_qian1[x-1]+chineseMoney; } if(chineseMoney=="") chineseMoney=chinese_number[0]; if(ling_qian!=undefined&&ling_qian!='00'){ chineseMoney+="圆"; for(a=0;a<=ling_qian.length-1;a++){ if(ling_qian.charAt(a)!='0') chineseMoney+=chinese_number[ling_qian.charAt(a)]+chinese_ling_qian[a]; } }else{ chineseMoney+="圆整"; } alert(chineseMoney); }