This example describes the JS implementation of the conversion of digital amounts to uppercase Chinese characters. Share to everyone for your reference, specific as follows:
The code looks like this: function convertcurrency (Money) {//kanji number var cnnums = new Array (' 0 ', ' one ', ' II ', ' San ', ' Restaurant ', ' Wu ', ' Lu ', ' qi ', ' ba
', ' nine ');
Base unit var cnintradice = new Array (', ' Pick ', ' bai ', ' thousand ');
Corresponding integer part of the extended unit var cnintunits = new Array (', ' million ', ' billion ', ' Mega ');
corresponding to the fractional unit var cndecunits = new Array (' Corner ', ' min ', ' Penny ', ' pct ');
The integer amount is followed by the character var Cninteger = ' whole ';
The unit var cnintlast = ' Yuan ' after the whole type is finished;
Max processing number var maxnum = 999999999999999.9999;
Amount of Integer part var integernum;
The amount of the small part of the Var decimalnum;
The Chinese amount of the output string var chinesestr = ';
The separated amount is used after the array, predefined var parts;
if (Money = = ") {return ';}
Money = parsefloat (money);
if (Money >= maxnum) {//exceeds maximum processing number return ';
} 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 integral partial conversion if (parseint (Integernum, > 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];
}//to 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 again to provide you with an online tool for your reference:
RMB Capital Online conversion Tool:
Http://tools.jb51.net/zhuanhuanqi/rmbupper
More readers interested in JavaScript-related content can view the site topics: "JavaScript Mathematical operational Usage Summary", "JavaScript data structure and algorithm skills summary", "JavaScript switching effects and techniques summary", " JavaScript Search Algorithm Tips Summary, "JavaScript animation effects and tips Summary", "JavaScript Errors and debugging skills summary" and "JavaScript traversal algorithm and Skills summary"
I hope this article will help you with JavaScript programming.