This article illustrates the method of JS to convert numerical amounts into capital RMB Chinese characters. Share it for your reference, as follows:
//The code is as follows: function convertCurrency(money) { //The Chinese characters' numbers var cnNums = new Array('zero', 'one', '2', 'three', 'si', '5', 'lu', '7', '8', 'nine'); //The basic unit var cnIntRadice = new Array('', 'shi', 'bai', 'qian'); //The corresponding integer part expansion unit var cnIntUnits = new Array('', '10, '10, '10, '10, '10, '10, '10, '10, '10, '10, '10, '10, '10, '10, '10, '10, '10, '10, '10, '10, '10, '10, '10, '10, '10, '10, '10, '10, '10, '10, '10, '10, '10, '10, '10, '10, '10, '10, '10, '10, '10, '10, '10, '10, '10, '10, '10, '10, '10, '10, '10, '10, '10, '10, '10, '10, '10, '10, '10, '10, '10, '10, '10, '10, '10, '10, '10, '10, '10, '10, '10, ' //The character var cnInteger followed by the integer amount var cnInteger = 'int'; //The unit var cnIntLast = 'yuan'; //The maximum processed number var maxNum = 999999999999.99999; //The integer part of the amount var integerNum; //The decimal part of the amount var decimalNum; //The output Chinese amount string var chineseStr = ''; //The array used after separating the amount, predefined var parts; if (money == '') { return ''; } money = parseFloat(money); if (money >= maxNum) { //The maximum processed number is exceeded ''; } if (money == 0) { chineseStr = cnNums[0] + cnIntLast + cnInteger; return chineseStr; } //Convert to string money = money.toString(); if (money.indexOf('.') == -1) { integerNum = money; decimalNum = ''; } else { parts = money.split('.'); integerNum = parts[0]; decimalNum = parts[1].substr(0, 4); } //Get integer partial conversion 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]; } //Zero zeroCount = 0; chineseStr += cnNums[parseInt(n)] + cnIntRadice[m]; } if (m == 0 && zeroCount < 4) { chineseStr += cnIntUnits[q]; } } chineseStr += cnIntLast; } //Decimal part if (decimalNum != '') { var decLen = decimalNum.length; for (var i = 0; i < decLen; i++) { var 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; } return chineseStr;}PS: Here is another online tool for your reference:
RMB capitalization online conversion tool:
http://tools.VeVB.COM/zhuanhuanqi/rmbupper
For more information about JavaScript related content, please check out the topics of this site: "Summary of JavaScript Mathematical Operation Usage", "Summary of JavaScript Data Structure and Algorithm Skills", "Summary of JavaScript Switching Special Effects and Skills", "Summary of JavaScript Search Algorithm Skills", "Summary of JavaScript Animation Special Effects and Skills", "Summary of JavaScript Errors and Debugging Skills" and "Summary of JavaScript Traversal Algorithm and Skills"
I hope this article will be helpful to everyone's JavaScript programming.