1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
| changeNumMoneyToChinese (money) { var cnNums = ['零', '壹', '贰', '叁', '肆', '伍', '陆', '柒', '捌', '玖'] var cnIntRadice = ['', '拾', '佰', '仟'] var cnIntUnits = ['', '万', '亿', '兆'] var cnDecUnits = ['角', '分', '毫', '厘'] var cnInteger = '整' var cnIntLast = '元' var maxNum = 999999999999999.9999 var IntegerNum var DecimalNum var ChineseStr = '' var parts var Symbol = '' if (money === '') { return }
money = parseFloat(money) if (money >= maxNum) { alert('超出最大处理数字') return '' } if (money === 0) { ChineseStr = cnNums[0] + cnIntLast + cnInteger return ChineseStr } if (money < 0) { money = -money Symbol = '负 ' } 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) { var zeroCount = 0 var IntLen = IntegerNum.length for (var i = 0; i < IntLen; i++) { var n = IntegerNum.substr(i, 1) var p = IntLen - i - 1 var q = p / 4 var 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 !== '') { var decLen = DecimalNum.length for (let i = 0; i < decLen; i++) { let n = DecimalNum.substr(i, 1) if (n !== '0') { ChineseStr += cnNums[Number(n)] + cnDecUnits[i] } } } if (ChineseStr === '') { ChineseStr += cnNums[0] + cnIntLast + cnInteger } else if (DecimalNum === '') { ChineseStr += cnInteger } ChineseStr = Symbol + ChineseStr
return ChineseStr }
}
|