首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > Web前端 >

数目字金额转换为中文大写金额

2012-06-29 
数字金额转换为中文大写金额自己的解决方案是整数部分4位一分组,每组对应一个大单位,组内对应小单位//yuyo

数字金额转换为中文大写金额
自己的解决方案是整数部分4位一分组,每组对应一个大单位,组内对应小单位

//yuyong 5-23var 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;}}elsetemp=chinese_number[a]+chinese_zheng_qian2[y]+temp;if(start==zheng_qian.length)break;elsestart++;}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);}

热点排行