1. function changeMoneyToChinese(money){  
  2.             var cnNums = new Array("零","壹","贰","叁","肆","伍","陆","柒","捌","玖"); //汉字的数字  
  3.             var cnIntRadice = new Array("","拾","佰","仟"); //基本单位  
  4.             var cnIntUnits = new Array("","万","亿","兆"); //对应整数部分扩展单位  
  5.             var cnDecUnits = new Array("角","分","毫","厘"); //对应小数部分单位  
  6.             //var cnInteger = "整"; //整数金额时后面跟的字符  
  7.             var cnIntLast = "元"//整型完以后的单位  
  8.             var maxNum = 999999999999999.9999; //最大处理的数字  
  9.               
  10.             var IntegerNum; //金额整数部分  
  11.             var DecimalNum; //金额小数部分  
  12.             var ChineseStr=""//输出的中文金额字符串  
  13.             var parts; //分离金额后用的数组,预定义  
  14.             if( money == "" ){  
  15.                 return "";  
  16.             }  
  17.             money = parseFloat(money);  
  18.             if( money >= maxNum ){  
  19.                 $.alert('超出最大处理数字');  
  20.                 return "";  
  21.             }  
  22.             if( money == 0 ){  
  23.                 //ChineseStr = cnNums[0]+cnIntLast+cnInteger;  
  24.                 ChineseStr = cnNums[0]+cnIntLast  
  25.                 //document.getElementById("show").value=ChineseStr;  
  26.                 return ChineseStr;  
  27.             }  
  28.             money = money.toString(); //转换为字符串  
  29.             if( money.indexOf(".") == -1 ){  
  30.                 IntegerNum = money;  
  31.                 DecimalNum = '';  
  32.             }else{  
  33.                 parts = money.split(".");  
  34.                 IntegerNum = parts[0];  
  35.                 DecimalNum = parts[1].substr(0,4);  
  36.             }  
  37.             if( parseInt(IntegerNum,10) > 0 ){//获取整型部分转换  
  38.                 zeroCount = 0;  
  39.                 IntLen = IntegerNum.length;  
  40.                 for( i=0;i<IntLen;i++ ){  
  41.                     n = IntegerNum.substr(i,1);  
  42.                     p = IntLen - i - 1;  
  43.                     q = p / 4;  
  44.                     m = p % 4;  
  45.                     if( n == "0" ){  
  46.                         zeroCount++;  
  47.                     }else{  
  48.                         if( zeroCount > 0 ){  
  49.                             ChineseStr += cnNums[0];  
  50.                         }  
  51.                         zeroCount = 0; //归零  
  52.                         ChineseStr += cnNums[parseInt(n)]+cnIntRadice[m];  
  53.                     }  
  54.                     if( m==0 && zeroCount<4 ){  
  55.                         ChineseStr += cnIntUnits[q];  
  56.                     }  
  57.                 }  
  58.                 ChineseStr += cnIntLast;  
  59.                 //整型部分处理完毕  
  60.             }  
  61.             if( DecimalNum!= '' ){//小数部分  
  62.                 decLen = DecimalNum.length;  
  63.                 for( i=0; i<decLen; i++ ){  
  64.                     n = DecimalNum.substr(i,1);  
  65.                     if( n != '0' ){  
  66.                         ChineseStr += cnNums[Number(n)]+cnDecUnits[i];  
  67.                     }  
  68.                 }  
  69.             }  
  70.             if( ChineseStr == '' ){  
  71.                 //ChineseStr += cnNums[0]+cnIntLast+cnInteger;  
  72.                 ChineseStr += cnNums[0]+cnIntLast;  
  73.             }/* else if( DecimalNum == '' ){ 
  74.                 ChineseStr += cnInteger; 
  75.                 ChineseStr += cnInteger; 
  76.             } */  
  77.             return ChineseStr;  
  78.         }  
posted on 2018-06-20 15:32  PandaZhang94  阅读(5111)  评论(0编辑  收藏  举报