Home >Web Front-end >JS Tutorial >Convert the amount from lower case to upper case in JS case sharing_javascript skills

Convert the amount from lower case to upper case in JS case sharing_javascript skills

WBOY
WBOYOriginal
2016-05-16 16:48:061278browse

When I was working on a project before, I encountered the need to automatically convert the amount entered in lowercase to uppercase. After some research, I came up with the following code and shared it with everyone. I hope it will be helpful

Copy code The code is as follows:

function Arabia_to_Chinese(Num){
for(i=Num.length-1; i>=0;i--)
{
Num = Num.replace(",","")
Num = Num.replace(" ","")
}
Num = Num.replace("¥","")
if(isNaN(Num)) {
alert("Please check whether the lowercase amount is correct");
return;
}
part = String(Num).split(".");
newchar = "";
for(i=part[0].length-1;i>=0;i--){
if(part[0].length > 10){ alert("The number of digits is too large to be calculated");return "";}
tmpnewchar = ""
perchar = part[0] .charAt(i);
switch(perchar){
case "0": tmpnewchar="zero" tmpnewchar ;break;
case "1": tmpnewchar="one" tmpnewchar ;break;
case "2": tmpnewchar="二" tmpnewchar ;break;
case "3": tmpnewchar="三" tmpnewchar ;break;
case "4": tmpnewchar="四" tmpnewchar ;break;
case "5": tmpnewchar="五" tmpnewchar ;break;
case "6": tmpnewchar="Lu" tmpnewchar ;break;
case "7": tmpnewchar="柒" tmpnewchar ;break;
case "8": tmpnewchar="捌" tmpnewchar ;break;
case "9": tmpnewchar="玖" tmpnewchar ;break;
}
switch(part[0].length- i-1){
case 0: tmpnewchar = tmpnewchar "元" ;break;
case 1: if(perchar!=0)tmpnewchar= tmpnewchar "十" ;break;
case 2: if( perchar!=0)tmpnewchar= tmpnewchar "䰰" ;break;
case 3: if(perchar!=0)tmpnewchar= tmpnewchar "千" ;break;
case 4: tmpnewchar= tmpnewchar "万" ;break ;
case 5: if(perchar!=0)tmpnewchar= tmpnewchar "hundred" ;break;
case 6: if(perchar!=0)tmpnewchar= tmpnewchar "hundred" ;break;
case 7 : if(perchar!=0)tmpnewchar= tmpnewchar "仟" ;break;
case 8: tmpnewchar= tmpnewchar "hundred million" ;break;
case 9: tmpnewchar= tmpnewchar "十" ;break;
}
newchar = tmpnewchar newchar;
}
if(Num.indexOf(".")!=-1){
if(part[1].length > 2) {
part[1] = part[1].substr(0,2)
}
for(i=0;itmpnewchar = ""
perchar = part[1].charAt(i)
switch(perchar){
case "0": tmpnewchar="zero" tmpnewchar ;break;
case "1": tmpnewchar="one " tmpnewchar ;break;
case "2": tmpnewchar="二" tmpnewchar ;break;
case "3": tmpnewchar="三" tmpnewchar ;break;
case "4": tmpnewchar="四" tmpnewchar ;break;
case "5": tmpnewchar="五" tmpnewchar ;break;
case "6": tmpnewchar="Lu" tmpnewchar ;break;
case "7": tmpnewchar= "柒" tmpnewchar ;break;
case "8": tmpnewchar="捌" tmpnewchar ;break;
case "9": tmpnewchar="玖" tmpnewchar ;break;
}
if( i==0)tmpnewchar =tmpnewchar "angle";
if(i==1)tmpnewchar = tmpnewchar "point";
newchar = newchar tmpnewchar;
}
}
while( newchar.search("zero zero") != -1)
newchar = newchar.replace("zero zero", "zero");
newchar = newchar.replace("zero billion", "hundred million" ; Zero yuan", "yuan");
newchar = newchar.replace("zero cent", "");
newchar = newchar.replace("zero cent", "");
if ( newchar.charAt(newchar.length-1) == "yuan" || newchar.charAt(newchar.length-1) == "angle")
newchar = newchar "whole"
return newchar;
}


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn