Use Java to convert the lower-case amount to the upper-case amount

Source: Internet
Author: User

Package com. tzsw. emhr. relieft. rttpub;

// Import Dori. Jasper. Engine .*;
Import java. util. arraylist;
Import java. Lang .*;

/**
* Number Conversion
*/

Public class convertnumber {// extends jrdefascripscriptlet
// Constructor
Public convertnumber (){
}

// Input lowercase numbers and return uppercase Chinese Characters
Private Static string convert (string number ){
Int num = 0;
String numstr = NULL;
Arraylist alist = new arraylist ();
Arraylist blist = new arraylist ();

Int longnum = number. Length ();
System. Out. println ("*** number ***:" + number );
Blist. Add ("zero ");
Blist. Add ("one ");
Blist. Add ("II ");
Blist. Add (" ");
Blist. Add ("Si ");
Blist. Add ("Wu ");
Blist. Add ("Lu ");
Blist. Add ("success ");
Blist. Add ("success ");
Blist. Add ("success ");
Blist. Add ("Ten Thousand ");
Blist. Add ("success ");
Blist. Add ("success ");
Blist. Add ("pick ");
Blist. Add ("Yuan ");
Blist. Add ("whole ");
For (INT I = 0; I <longnum; I ++ ){
Numstr = number. substring (I, I + 1 );
Num = integer. parseint (numstr );
Numstr = (string) blist. Get (Num );
Alist. Add (numstr );
If (num! = 0 ){
Num = number. substring (I). Length ();
If (num = 5 ){
Alist. Add (blist. Get (10 ));
}
If (num = 4 ){
Alist. Add (blist. Get (11 ));
}
If (num = 3 ){
Alist. Add (blist. Get (12 ));
}
If (num = 2 ){
Alist. Add (blist. Get (13 ));
}
}
}

Longnum = alist. Size ();
For (INT I = longnum-1; I> = 0; I --){
If (alist. Get (I). Equals (blist. Get (0 ))){
Alist. Remove (I );
}
Else {
Break;
}
}

Longnum = alist. Size ();
For (INT I = 0; I <longNum-2; I ++ ){
If (alist. get (I ). equals (blist. get (0) & alist. get (I + 1 ). equals (blist. get (0) & alist. get (I + 2 ). equals (blist. get (0 ))){
Alist. Remove (I );
Alist. Remove (I + 1 );
I ++;
}
}

Longnum = alist. Size ();
For (INT I = 0; I <longNum-1; I ++ ){
If (alist. Get (I). Equals (blist. Get (0) & alist. Get (I + 1). Equals (blist. Get (0 ))){
Alist. Remove (I );
}
}

Longnum = alist. Size ();
Numstr = "";
For (INT I = 0; I <longnum; I ++ ){
Numstr + = (string) alist. Get (I );
}

Return numstr;
}

// Convert the decimal part
Public String convertsmlnumber (string number ){
Arraylist clist = new arraylist ();
Arraylist blist = new arraylist ();
Blist. Add ("zero ");
Blist. Add ("one ");
Blist. Add ("II ");
Blist. Add (" ");
Blist. Add ("Si ");
Blist. Add ("Wu ");
Blist. Add ("Lu ");
Blist. Add ("success ");
Blist. Add ("success ");
Blist. Add ("success ");

Clist. Add ("Yuan ");
Clist. Add (" ");
Clist. Add ("points ");
Clist. Add ("PCT ");

String strnum = "";
String rtnstr = "";
Int num = 0;
If (number. Length ()> 3 ){
Strnum = number. substring (0, 3 );
} Else {
Strnum = number;
}
For (INT I = 0; I <strnum. Length (); I ++ ){
If (I = 0 ){
Rtnstr + = (string) clist. Get (I );
}
Num = integer. parseint (strnum. substring (I, I + 1 ));
Rtnstr + = (string) blist. Get (Num );
If (num! = 0 ){
Rtnstr + = (string) clist. Get (I + 1 );
}
}
// Remove the "zero" contact at the end"
While (rtnstr. substring (rtnstr. Length ()-1, rtnstr. Length (). Equals (blist. Get (0 ))){
Rtnstr = rtnstr. substring (0, rtnstr. Length ()-1 );
}
// If the two links in the middle are zero, remove one
For (INT m = 0; m <rtnstr. Length ()-1; m ++ ){
If (rtnstr. substring (M, m + 1). Equals (rtnstr. substring (m + 1, m + 2 ))){
Rtnstr = rtnstr. substring (0, m) + rtnstr. substring (m + 1, rtnstr. Length ());
}
}
Return rtnstr;
}

Public String convertnumber (string number ){
String numberstr = "";
Boolean flag = false;
Arraylist blist = new arraylist ();
Blist. Add ("Yuan ");
Blist. Add ("Ten Thousand ");
Blist. Add (" ");

// Determine whether it is a floating point number"
Int num = number. indexof (".");
String substr = "";
If (num! =-1 ){
// If (integer. parseint (number. substring (Num + 1, number. Length ()> 0 ){
// Number = "" + (integer. parseint (number. substring (0, num) + 1 );
//}
// Else {
Substr = number. substring (Num + 1, number. Length ());
Flag = true;
Number = "" + integer. parseint (number. substring (0, num ));

//}
}

Num = number. Length ();
Arraylist alist = new arraylist ();
While (Num> 0 ){
If (Num> = 4 ){
Alist. Add (number. substring (Num-4, num ));
}
If (Num <4 & num> 0 ){
Alist. Add (number. substring (0, num ));
}
Num = num-4;
}
Num = alist. Size ();
System. Out. println ("Num:" + num );
While (Num> 0 ){
Numberstr + = convertnumber. Convert (alist. Get (Num-1). tostring () +
Blist. Get (Num-1 );
Num --;
}
// Process floating point numbers
If (flag = true & integer. parseint (substr )! = 0 ){
Numberstr = numberstr. substring (0, numberstr. Length ()-2) + convertsmlnumber (substr );
}
Return numberstr;
}

Public static void main (string [] ARGs ){
Convertnumber cnum = new convertnumber ();
String strnum= "100000090.0000 ";
String STR = cnum. convertnumber (strnum );
System. Out. println (STR );
}
}

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.