Convert JavaScript Arabic numerals to Chinese uppercase

Source: Internet
Author: User

Method 1:

 

Function dx (n) {// converts the amount in uppercase.
If
(! /^ (0 | [1-9] \ D *) (\. \ D + )? $/. Test (n ))
Return "invalid data ";
VaR unit =
"Hundreds of thousands of yuan corner points", STR = "";
N + = "00 ";
VaR P = n. indexof ('.');
If (P
> = 0)
N = n. substring (0, P) + N. substr (p + 1, 2 );
Unit =
Unit. substr (unit. Length-N. Length );
For (VAR I = 0; I <n. length;
I ++)
STR + = 'zero character (I) + unit. charat (N. charat (I );
Return
Str. replace (/0 (Thousands | hundreds | pick | corners)/g, "zero "). replace (/(zero) +/g, "zero "). replace (/0 (| RMB)/g,
"$1"). Replace (/(million) | Yi (pick)/g, "$1 $2"). Replace (/^ RMB 0? | Zero/g, ""). Replace (/$/g,
"RMB ");
}

 

Method 2:

Function I2C (n ){
If (typeof (n) = "Number "){
If (-1 =
N. tostring (). indexof (".")){
Return seti2c (N );
} Else {
VaR
I, istr, F, fstr, A, rstr;
A = n. tostring (). Split (".");
I = A [0];
F =
A [1];
Istr = seti2c (I );
Fstr = setf2c (f );
Rstr = istr + "zero" + fstr;
Rstr
= Rstr. Replace (/0 +/g, "0 ");
Return rstr;
}
} Else {
Return
"---";
}
}

Function seti2c (n ){
VaR NS = n. tostring ();
VaR tempstr = "";
For (VAR
I = 1; I <ns. Length + 1; I ++ ){
Switch (I ){
Case 1:
VaR T =
NS. substr (NS. Length-I, 1 );
If (T! = "0 "){
Tempstr =
T + "circle" + tempstr;
} Else {
Tempstr = "circle" + tempstr;
}
Break;
Case
2:
VaR T = NS. substr (NS. Length-I, 1 );
If (T! = "0 "){
Tempstr =
T + "pick" + tempstr;
} Else {
Tempstr = "0" + tempstr;
}
Break;
Case
3:
VaR T = NS. substr (NS. Length-I, 1 );
If (T! = "0 "){
Tempstr =
T + "batch" + tempstr;
} Else {
Tempstr = "0" + tempstr;
}
Break;
Case
4:
VaR T = NS. substr (NS. Length-I, 1 );
If (T! = "0 "){
Tempstr =
T + "batch" + tempstr;
} Else {
Tempstr = "0" + tempstr;
}
Break;
Case
5:
VaR T = NS. substr (NS. Length-I, 1 );
If (T! = "0 "){
Tempstr =
T + "Ten Thousand" + tempstr;
} Else {
Tempstr = "Ten Thousand" + tempstr;
}
Break;
Case
6:
VaR T = NS. substr (NS. Length-I, 1 );
If (T! = "0 "){
Tempstr =
T + "pick" + tempstr;
} Else {
Tempstr = "0" + tempstr;
}
Break;
Case
7:
VaR T = NS. substr (NS. Length-I, 1 );
If (T! = "0 "){
Tempstr =
T + "batch" + tempstr;
} Else {
Tempstr = "0" + tempstr;
}
Break;
Case
8:
VaR T = NS. substr (NS. Length-I, 1 );
If (T! = "0 "){
Tempstr =
T + "batch" + tempstr;
} Else {
Tempstr = "0" + tempstr;
}
Break;
Case
9:
VaR T = NS. substr (NS. Length-I, 1 );
If (T! = "0 "){
Tempstr =
T + "" + tempstr;
} Else {
Tempstr = "" + tempstr;
}
Break;
Case
10:
VaR T = NS. substr (NS. Length-I, 1 );
If (T! = "0 "){
Tempstr =
T + "pick" + tempstr;
} Else {
Tempstr = "0" + tempstr;
}
Break;
Case
11:
VaR T = NS. substr (NS. Length-I, 1 );
If (T! = "0 "){
Tempstr =
T + "batch" + tempstr;
} Else {
Tempstr = "0" + tempstr;
}
Break;
Case
12:
VaR T = NS. substr (NS. Length-I, 1 );
If (T! = "0 "){
Tempstr =
T + "batch" + tempstr;
} Else {
Tempstr =
"0" + tempstr;
}
Break;
Default: break;
}
}
Return
G2b (tempstr );
}

Function setf2c (n ){
VaR NS = n. tostring ();
VaR tempstr = "";
For (VAR
I = 0; I <ns. length; I ++ ){
Switch (I ){
Case 0:
VaR T =
NS. substr (I, 1 );
If (T! = "0 "){
Tempstr + = T + "";
} Else {
Tempstr + =
"0 ";
}
Break;
Case 1:
VaR T =
NS. substr (I, 1 );
If (T! = "0 "){
Tempstr + =
T + "points ";
}
Break;
Default: break;
}
}
Return
G2b (tempstr );
}

Function g2b (s ){
Rs = S. Replace (/0 +/g, "0 ");
Rs =
Rs. Replace ("0 circle", "circle ");
Rs = Rs. Replace ("0 billion ");
Rs =
Rs. Replace ("0 thousand ");
Rs = Rs. Replace ("hundreds of millions", "hundreds of millions ");
Rs =
Rs. Replace (/0/G, "0 ");
Rs = Rs. Replace (/1/g, "1 ");
Rs =
Rs. Replace (/2/g, "er ");
Rs = Rs. Replace (/3/g, "");
Rs =
Rs. Replace (/4/g, "Si ");
Rs = Rs. Replace (/5/g, "Wu ");
Rs =
Rs. Replace (/6/g, "");
Rs = Rs. Replace (/7/g, "replace ");
Rs =
Rs. Replace (/8/g, "replace ");
Rs = Rs. Replace (/9/g, "replace ");
Return Rs;
}

Method 1:

 

Function dx (n) {// converts the amount in uppercase.
If
(! /^ (0 | [1-9] \ D *) (\. \ D + )? $/. Test (n ))
Return "invalid data ";
VaR unit =
"Hundreds of thousands of yuan corner points", STR = "";
N + = "00 ";
VaR P = n. indexof ('.');
If (P
> = 0)
N = n. substring (0, P) + N. substr (p + 1, 2 );
Unit =
Unit. substr (unit. Length-N. Length );
For (VAR I = 0; I <n. length;
I ++)
STR + = 'zero character (I) + unit. charat (N. charat (I );
Return
Str. replace (/0 (Thousands | hundreds | pick | corners)/g, "zero "). replace (/(zero) +/g, "zero "). replace (/0 (| RMB)/g,
"$1"). Replace (/(million) | Yi (pick)/g, "$1 $2"). Replace (/^ RMB 0? | Zero/g, ""). Replace (/$/g,
"RMB ");
}

 

Method 2:

Function I2C (n ){
If (typeof (n) = "Number "){
If (-1 =
N. tostring (). indexof (".")){
Return seti2c (N );
} Else {
VaR
I, istr, F, fstr, A, rstr;
A = n. tostring (). Split (".");
I = A [0];
F =
A [1];
Istr = seti2c (I );
Fstr = setf2c (f );
Rstr = istr + "zero" + fstr;
Rstr
= Rstr. Replace (/0 +/g, "0 ");
Return rstr;
}
} Else {
Return
"---";
}
}

Function seti2c (n ){
VaR NS = n. tostring ();
VaR tempstr = "";
For (VAR
I = 1; I <ns. Length + 1; I ++ ){
Switch (I ){
Case 1:
VaR T =
NS. substr (NS. Length-I, 1 );
If (T! = "0 "){
Tempstr =
T + "circle" + tempstr;
} Else {
Tempstr = "circle" + tempstr;
}
Break;
Case
2:
VaR T = NS. substr (NS. Length-I, 1 );
If (T! = "0 "){
Tempstr =
T + "pick" + tempstr;
} Else {
Tempstr = "0" + tempstr;
}
Break;
Case
3:
VaR T = NS. substr (NS. Length-I, 1 );
If (T! = "0 "){
Tempstr =
T + "batch" + tempstr;
} Else {
Tempstr = "0" + tempstr;
}
Break;
Case
4:
VaR T = NS. substr (NS. Length-I, 1 );
If (T! = "0 "){
Tempstr =
T + "batch" + tempstr;
} Else {
Tempstr = "0" + tempstr;
}
Break;
Case
5:
VaR T = NS. substr (NS. Length-I, 1 );
If (T! = "0 "){
Tempstr =
T + "Ten Thousand" + tempstr;
} Else {
Tempstr = "Ten Thousand" + tempstr;
}
Break;
Case
6:
VaR T = NS. substr (NS. Length-I, 1 );
If (T! = "0 "){
Tempstr =
T + "pick" + tempstr;
} Else {
Tempstr = "0" + tempstr;
}
Break;
Case
7:
VaR T = NS. substr (NS. Length-I, 1 );
If (T! = "0 "){
Tempstr =
T + "batch" + tempstr;
} Else {
Tempstr = "0" + tempstr;
}
Break;
Case
8:
VaR T = NS. substr (NS. Length-I, 1 );
If (T! = "0 "){
Tempstr =
T + "batch" + tempstr;
} Else {
Tempstr = "0" + tempstr;
}
Break;
Case
9:
VaR T = NS. substr (NS. Length-I, 1 );
If (T! = "0 "){
Tempstr =
T + "" + tempstr;
} Else {
Tempstr = "" + tempstr;
}
Break;
Case
10:
VaR T = NS. substr (NS. Length-I, 1 );
If (T! = "0 "){
Tempstr =
T + "pick" + tempstr;
} Else {
Tempstr = "0" + tempstr;
}
Break;
Case
11:
VaR T = NS. substr (NS. Length-I, 1 );
If (T! = "0 "){
Tempstr =
T + "batch" + tempstr;
} Else {
Tempstr = "0" + tempstr;
}
Break;
Case
12:
VaR T = NS. substr (NS. Length-I, 1 );
If (T! = "0 "){
Tempstr =
T + "batch" + tempstr;
} Else {
Tempstr =
"0" + tempstr;
}
Break;
Default: break;
}
}
Return
G2b (tempstr );
}

Function setf2c (n ){
VaR NS = n. tostring ();
VaR tempstr = "";
For (VAR
I = 0; I <ns. length; I ++ ){
Switch (I ){
Case 0:
VaR T =
NS. substr (I, 1 );
If (T! = "0 "){
Tempstr + = T + "";
} Else {
Tempstr + =
"0 ";
}
Break;
Case 1:
VaR T =
NS. substr (I, 1 );
If (T! = "0 "){
Tempstr + =
T + "points ";
}
Break;
Default: break;
}
}
Return
G2b (tempstr );
}

Function g2b (s ){
Rs = S. Replace (/0 +/g, "0 ");
Rs =
Rs. Replace ("0 circle", "circle ");
Rs = Rs. Replace ("0 billion ");
Rs =
Rs. Replace ("0 thousand ");
Rs = Rs. Replace ("hundreds of millions", "hundreds of millions ");
Rs =
Rs. Replace (/0/G, "0 ");
Rs = Rs. Replace (/1/g, "1 ");
Rs =
Rs. Replace (/2/g, "er ");
Rs = Rs. Replace (/3/g, "");
Rs =
Rs. Replace (/4/g, "Si ");
Rs = Rs. Replace (/5/g, "Wu ");
Rs =
Rs. Replace (/6/g, "");
Rs = Rs. Replace (/7/g, "replace ");
Rs =
Rs. Replace (/8/g, "replace ");
Rs = Rs. Replace (/9/g, "replace ");
Return Rs;
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.