This article has shared with you the relevant code for converting js amount to capitalization for your reference. The specific content is as follows
function convertCurrency(num) { //Convert to RMB capital amount form var str1 = 'zero one23354789'; //The Chinese character var str2 corresponding to 0-9 = '10,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,0 Math.abs(num).toFixed(2); //Take the absolute value of num and round it into 2 decimal places str4 = (num * 100).toFixed(0).toString(); //Multiple num 100 and convert it into a string form j = str4.length; //Find out the highest bit if (j > 15) { return 'overflow'; } str2 = str2.substr(15 - j); //Take out the value of str2 of the corresponding number of digits. For example: 200.55, j is 5, so str2=Bai Shiyuan Angle segments//Cycle to extract the value that needs to be converted for (i = 0; i str3 = str4.substr(i, 1); //Fetch the value of a certain bit to be converted if (i != (j - 3) && i != (j - 7) && i != (j - 11) && i != (j - 15)) { //When the number of bits taken is not a number of 1, 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, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, + str1.substr(str3 * 1, 1); ch2 = str2.substr(i, 1); nzero = 0; } else { ch1 = str1.substr(str3 * 1, 1); ch2 = str2.substr(i, 1); nzero = 0; } } } else { //This bit is a key bit such as trillion, billion, million, and yuan bits if (str3 != '0' && nzero != 0) { ch1 = "zero" + str1.substr(str3 * 1, 1); ch2 = str2.substr(i, 1); nzero = 0; } else { if (str3 != '0' && nzero == 0) { ch1 = str1.substr(str3 * 1, 1); ch2 = str2.substr(i, 1); nzero = 0; } else { if (str3 == '0' && nzero >= 3) { ch1 = ''; ch2 = ''; nzero = nzero + 1; } else { if (j >= 11) { ch1 = ''; nzero = nzero + 1; } else { ch1 = ''; ch2 = str2.substr(i, 1); nzero = nzero + 1; } } } } } if (i == (j - 11) || i == (j - 3)) { //If this bit is a billion or a digit, you must write ch2 = str2.substr(i, 1); } str5 = str5 + ch1 + ch2; if (i == j - 1 && str3 == '0') { //When the last bit (mine) is 0, add "integral" str5 = str5 + 'integral'; } } if (num == 0) { str5 = 'zero-center'; } if (str5.indexOf("mine") == -1) { if (str5.indexOf("selection zero") > 0) { str5 = str5.replace("Shiyuan Zero", "Shiyuan"); }; } return str5;} function doConvert(m, n) { Ext.getCmp(m).on('change', function() { var objm = Ext.getCmp(m); var objn = Ext.getCmp(n); if (!(/^/d+(/./d+)?$/.test(objm.getValue()))) { objn.setValue(""); } else { var money = convertCurrency(objm.getValue()); if (objm.getValue() == "") { objn.setValue(""); } else { objn.setValue(money); } } var money = convertCurrency(objm.getValue()); if (money.indexOf("Shiyuan Zero") > 0) { if (money.indexOf("Shiyuan Zero") == -1) { objn.setValue(money.replace("Shiyuan Zero", "Shiyuan")); } }; });}The above is all about this article, I hope it will be helpful for everyone to learn JavaScript programming.