JS function that converts numbers into capital RMB expressions
There are many ways to convert numbers into capital RMB. This example introduces the use of js to complete it. Check out the implementation code below
function changeNumMoneyToChinese(money) { var cnNums = new Array("zero", "one", "two", "Three", "Si", "Wu", "land", "Qi", "eight", "Nine"); // Chinese characters number var cnIntRadice = new Array("", "pickup", "Bai", "thousand"); //Basic unit var cnIntUnits = new Array("", "Ten thousand", "100 million", "mega"); //The corresponding integer part expansion unit var cnDecUnits = new Array("horn", "point", "Blog", "Qi"); //The corresponding decimal unit var cnInteger = "all"; //The characters followed by the integer amount var cnIntLast = "Yuan"; //Unit after the whole modeling var maxNum = 999999999999999.9999; //Maximum number processed var IntegerNum; //Amount integer part var DecimalNum; //Decimal part of the amount var ChineseStr = ""; //The output Chinese amount string var parts; //Array used after separating the amount, predefined if (money == "") { return ""; } money = parseFloat(money); if (money >= maxNum) { alert('Exceeding maximum processing number'); return ""; } if (money == 0) { ChineseStr = cnNums[0] + cnIntLast + cnInteger; return ChineseStr; } money = (); //Convert to string if ((".") == -1) { IntegerNum = money; DecimalNum = ''; } else { parts = ("."); IntegerNum = parts[0]; DecimalNum = parts[1].substr(0, 4); } if (parseInt(IntegerNum, 10) > 0) { //Get the integer partial conversion var zeroCount = 0; var IntLen = ; for (var i = 0; i < IntLen; i++) { var n = (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; //Return to zero ChineseStr += cnNums[parseInt(n)] + cnIntRadice[m]; } if (m == 0 && zeroCount < 4) { ChineseStr += cnIntUnits[q]; } } ChineseStr += cnIntLast; //The integer part has been processed } if (DecimalNum != '') { //Decimal Part var decLen = ; for (var i = 0; i < decLen; i++) { var n = (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; }
Related Articles
How to use Microsoft's text to voice service on uni-app
With voice recognition, communication becomes very simple. The following article mainly introduces relevant information on how to use Microsoft's text-to-voice service on uni-app. Friends who need it can refer to it.2022-06-06Dynamically generated IFRAME, the impact of different locations when setting SRC
Dynamically generated IFRAME, the impact of different locations when setting SRC. What is mentioned below is running under IE7. The same is true for IE6. In this blog, directly clicking to run the code, and the effect is different from saving the following code to a web page (accessed as a local file or domain name).2008-03-03How to get USB QR code scan gun data
This article mainly introduces in detail how to obtain USB QR code scan gun data for js. The sample code in the article is introduced in detail and has a certain reference value. Interested friends can refer to it.2021-09-09js regular matching of multiple all data problems
This article mainly introduces the problem of js regular matching of multiple data. This article introduces you in very detailed ways in two ways, and has certain reference value. Friends who need it can refer to it.2019-12-12JS lottery achieves random lottery code effect
This article mainly introduces the effect of js random lottery code, please refer to it2013-12-12WeChat mini program imitates the headline navigation bar scroll analysis
This article mainly introduces the scroll analysis of WeChat mini-program imitating the headline navigation bar. The example code is introduced in this article in detail, which has certain reference value for everyone's study or work. Friends who need it can refer to it.2019-08-08Implementing Snake Games based on JavaScript
This article mainly introduces the implementation of the Snake Game based on JavaScript. The sample code in the article is introduced in detail and has a certain reference value. Interested friends can refer to it.2020-03-03Take your hands to get started with the use of the new WeChat mini program Kbone
This article mainly introduces the use of Kbone, a new framework of WeChat applet. The example code is introduced in this article in detail, which has certain reference learning value for everyone's study or work. Friends who need it, please learn with the editor below.2020-02-02How to generate QR code with pictures based on native javascript
This article mainly introduces how to generate QR codes with pictures based on native javaScript. The example code is introduced in this article in detail, which has certain reference value for everyone's learning or work. Friends who need it can refer to it.2019-11-11Use JS to implement simple login verification function
This article mainly introduces the use of JS to implement simple login verification function. The code is simple and easy to understand, very good, and has reference value. If you need it, please refer to it.2017-07-07