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