Convert renminbi to uppercase

zhaozj2021-02-16  50

Write a functional function with JavaScript to complete the following features:

1. For a given string, such as: 1234.55, convert to the correct Chinese currency description: such as: RMB 壹 贰 叁 叁 四 四 五五 五

2, the input string form can be the following: with points, such as: 123, 456, 789.00; without separators, such as: 123456789

3, the output of the Chinese currency description should comply with specifications, such as: 0.3 ---- RMB triangle; 0.33 ---- RMB triangle three points; 1 ---- RMB 元 100 ---- RMB 元 元; 1001 ---- RMB 壹 仟 零 元 整; 10000001 ---- RMB 壹 万 零 元 元; 1001001 ---- RMB 壹仟 零 壹 万 零 壹 元,

4, maximum conversion can go to 10 billion

The specific code is as follows:

</ title> <script language = "jscript"> function convertcurrency (currencydigits) {///// Constants: var MAXIMUM_NUMBER = 99999999999.99; // Predefine the radix characters and currency symbols for output: var CN_ZERO = "zero"; var CN_ONE = "One"; var CN_TWO = "II"; var CN_THREE = "three"; var CN_FOUR = ""; Var cn_five = "Wu"; var cn_six = "land"; var cn_seven = "柒"; var cn_eight = "柒"; var cn_nine = "玖"; var cn_ten = "Pick"; var cn_hundred = " "; Var cn_thousand =" 仟 "; var cn_ten_thousand =" 10,000 "; var cn_hundred_million =" 100 million "; var cn_symbol =" RMB "; var cn_dollar =" yuan "; var cn_ten_cent =" angle "; var cn_cent =" "; var CN_INTEGER =" integer "; // Variables: var integral; // Represent integral part of digit number var decimal; // Represent decimal part of digit number var outputCharacters; // The output result var parts; var... DIGITS, RADICES, BIGRADICES, DECIMALS; VAR ZEROCOUNT; VAR I, P, D; Var Quotient, MODULUS; // Validate Input String : Currencydigits = currencydigits.tostring (); if (currencydigits == ") {Alert (" Empty Input! "); Return" ";} if (currencydigits.match (/[1) (/[ ^ ,./ D] /)! = NULL) {Alert ("Invalid Characters in The Input String!"); Return "";} IF ((currencydigits) .MATCH (/ ^ ((/ ^ (1, 3} (, / D {3}) * ( ((/ D {3},))?) | (/ D (./ D )?)) $ /) == null) {Alert ("Illegal format of digit number ! ");"</p> <p>Return "";} // normalize the format of infut digits: currencydigits = currencydigits.Replace (/, / g, ""); // Remove Comma Delimiters. currencydigits = currencydigits.replace (/ ^ 0 /, "") ; // assrt the number is not well "> maximum_number) {Alert (" TO LARGE A Number To Convert! "); Return"; // Process the coversion from currency digits to characters: // Separate integral and decimal parts before processing coversion: parts = currencyDigits.split ( "."); if (parts.length> 1) {integral = parts [0]; decimal = Parts [1]; // Cut Down Redundant Decimal Digits That Are Instimal.Substr (0, 2);} else {integral = parts [0]; decimal = ";} // prepare the characters corresponding to the digits: digits = new Array (CN_ZERO, CN_ONE, CN_TWO, CN_THREE, CN_FOUR, CN_FIVE, CN_SIX, CN_SEVEN, CN_EIGHT, CN_NINE); radices = new Array ( "", CN_TEN, CN_HUNDRED, CN_THOUSAND); bigRadices = new Ar ray ( "", CN_TEN_THOUSAND, CN_HUNDRED_MILLION); decimals = new Array (CN_TEN_CENT, CN_CENT); // Start processing: outputCharacters = ""; // Process integral part if it is larger than 0: if (Number (integral)> 0 ) {Zerocount = 0; for (i = 0; I <integral.length; i ) {p = integral.length - i - 1; d = integral.substr (i, 1); quotient = p / 4; moduts = P% 4; IF (D == "0") {zerocount ;} else {if (zerocount> 0) {OutputCharacters = DIGITS [0];} zerocount = 0; OutputCharacters =</p> <p>digits [Number (d)] radices [modulus];} if (modulus == 0 && zeroCount <4) {outputCharacters = bigRadices [quotient];}} outputCharacters = CN_DOLLAR;} // Process decimal part if there is : IF (Decimal! = "") {For (i = 0; i <decimal.length; i ) {d = decimal.substr (i, 1); if (d! = "0") {OutputCharacters = DIGITS [Number (D)] Decimals [I];}}} // Confirm and Return The final output string: IF (outputcharacters == ") {OutputCharacters = CN_ZERO CN_DOLLAR;} if (decimal ==") { outputCharacters = CN_INTEGER;} outputCharacters = CN_SYMBOL outputCharacters; return outputCharacters;} </ script> </ head> <body> <INPUT id = "Digits" type = "text" name = "Digits" size = 20> <INPUT ID = "confert" type = "" value = "confert" name = "οnclick =" = "οnclick =" = "οnclick ="> "> <input =" result "type =" text "Name = "Result" size = 60> </ body> </ html> The above code uses the function of the regular expression, in addition to the correct way to convert to RMB, it is also possible to determine if the input form is correct.</p></div><div class="text-center mt-3 text-grey"> 转载请注明原文地址:https://www.9cbs.com/read-22049.html</div><div class="plugin d-flex justify-content-center mt-3"></div><hr><div class="row"><div class="col-lg-12 text-muted mt-2"><i class="icon-tags mr-2"></i><span class="badge border border-secondary mr-2"><h2 class="h6 mb-0 small"><a class="text-secondary" href="tag-2.html">9cbs</a></h2></span></div></div></div></div><div class="card card-postlist border-white shadow"><div class="card-body"><div class="card-title"><div class="d-flex justify-content-between"><div><b>New Post</b>(<span class="posts">0</span>) </div><div></div></div></div><ul class="postlist list-unstyled"> </ul></div></div><div class="d-none threadlist"><input type="checkbox" name="modtid" value="22049" checked /></div></div></div></div></div><footer class="text-muted small bg-dark py-4 mt-3" id="footer"><div class="container"><div class="row"><div class="col">CopyRight © 2020 All Rights Reserved </div><div class="col text-right">Processed: <b>0.040</b>, SQL: <b>9</b></div></div></div></footer><script src="./lang/en-us/lang.js?2.2.0"></script><script src="view/js/jquery.min.js?2.2.0"></script><script src="view/js/popper.min.js?2.2.0"></script><script src="view/js/bootstrap.min.js?2.2.0"></script><script src="view/js/xiuno.js?2.2.0"></script><script src="view/js/bootstrap-plugin.js?2.2.0"></script><script src="view/js/async.min.js?2.2.0"></script><script src="view/js/form.js?2.2.0"></script><script> var debug = DEBUG = 0; var url_rewrite_on = 1; var url_path = './'; var forumarr = {"1":"Tech"}; var fid = 1; var uid = 0; var gid = 0; xn.options.water_image_url = 'view/img/water-small.png'; </script><script src="view/js/wellcms.js?2.2.0"></script><a class="scroll-to-top rounded" href="javascript:void(0);"><i class="icon-angle-up"></i></a><a class="scroll-to-bottom rounded" href="javascript:void(0);" style="display: inline;"><i class="icon-angle-down"></i></a></body></html><script> var forum_url = 'list-1.html'; var safe_token = 'e2w5buQ7WiSJbM56fJhdxjTiCMISMuQ2t_2B45yG5ZSE4p5qaFVrffFBuee3wVVsH1_2BnOJ4ZRlOjEi_2FvbU'; var body = $('body'); body.on('submit', '#form', function() { var jthis = $(this); var jsubmit = jthis.find('#submit'); jthis.reset(); jsubmit.button('loading'); var postdata = jthis.serializeObject(); $.xpost(jthis.attr('action'), postdata, function(code, message) { if(code == 0) { location.reload(); } else { $.alert(message); jsubmit.button('reset'); } }); return false; }); function resize_image() { var jmessagelist = $('div.message'); var first_width = jmessagelist.width(); jmessagelist.each(function() { var jdiv = $(this); var maxwidth = jdiv.attr('isfirst') ? first_width : jdiv.width(); var jmessage_width = Math.min(jdiv.width(), maxwidth); jdiv.find('img, embed, iframe, video').each(function() { var jimg = $(this); var img_width = this.org_width; var img_height = this.org_height; if(!img_width) { var img_width = jimg.attr('width'); var img_height = jimg.attr('height'); this.org_width = img_width; this.org_height = img_height; } if(img_width > jmessage_width) { if(this.tagName == 'IMG') { jimg.width(jmessage_width); jimg.css('height', 'auto'); jimg.css('cursor', 'pointer'); jimg.on('click', function() { }); } else { jimg.width(jmessage_width); var height = (img_height / img_width) * jimg.width(); jimg.height(height); } } }); }); } function resize_table() { $('div.message').each(function() { var jdiv = $(this); jdiv.find('table').addClass('table').wrap('<div class="table-responsive"></div>'); }); } $(function() { resize_image(); resize_table(); $(window).on('resize', resize_image); }); var jmessage = $('#message'); jmessage.on('focus', function() {if(jmessage.t) { clearTimeout(jmessage.t); jmessage.t = null; } jmessage.css('height', '6rem'); }); jmessage.on('blur', function() {jmessage.t = setTimeout(function() { jmessage.css('height', '2.5rem');}, 1000); }); $('#nav li[data-active="fid-1"]').addClass('active'); </script>