- function changeMoneyToChinese(money){
- var cnNums = new Array("零","壹","贰","叁","肆","伍","陆","柒","捌","玖");
- var cnIntRadice = new Array("","拾","佰","仟");
- var cnIntUnits = new Array("","万","亿","兆");
- var cnDecUnits = new Array("角","分","毫","厘");
-
- var cnIntLast = "元";
- var maxNum = 999999999999999.9999;
-
- var IntegerNum;
- var DecimalNum;
- var ChineseStr="";
- var parts;
- if( money == "" ){
- return "";
- }
- money = parseFloat(money);
- if( money >= maxNum ){
- $.alert('超出最大处理数字');
- return "";
- }
- if( money == 0 ){
-
- ChineseStr = cnNums[0]+cnIntLast
-
- return ChineseStr;
- }
- money = money.toString();
- if( money.indexOf(".") == -1 ){
- IntegerNum = money;
- DecimalNum = '';
- }else{
- parts = money.split(".");
- IntegerNum = parts[0];
- DecimalNum = parts[1].substr(0,4);
- }
- if( parseInt(IntegerNum,10) > 0 ){
- zeroCount = 0;
- IntLen = IntegerNum.length;
- for( i=0;i<IntLen;i++ ){
- n = IntegerNum.substr(i,1);
- p = IntLen - i - 1;
- q = p / 4;
- m = p % 4;
- if( n == "0" ){
- zeroCount++;
- }else{
- if( zeroCount > 0 ){
- ChineseStr += cnNums[0];
- }
- zeroCount = 0;
- ChineseStr += cnNums[parseInt(n)]+cnIntRadice[m];
- }
- if( m==0 && zeroCount<4 ){
- ChineseStr += cnIntUnits[q];
- }
- }
- ChineseStr += cnIntLast;
-
- }
- if( DecimalNum!= '' ){
- decLen = DecimalNum.length;
- for( i=0; i<decLen; i++ ){
- n = DecimalNum.substr(i,1);
- if( n != '0' ){
- ChineseStr += cnNums[Number(n)]+cnDecUnits[i];
- }
- }
- }
- if( ChineseStr == '' ){
-
- ChineseStr += cnNums[0]+cnIntLast;
- }
- return ChineseStr;
- }
posted on
2018-06-20 15:32
PandaZhang94
阅读(
5111)
评论()
编辑
收藏
举报