The amount of Java Arabic numerals is converted into Chinese capital amount

Source: Internet
Author: User

Maximum number to be processed to hundreds of billions
That's 12 bits.
Integer part we can be divided into 3 paragraph processing, XXXX billion, XXXX million, XXXX Yuan, and then the fractional part is better processed
We found 0 more difficult to handle.
When does 0 come up?
That is, there is one or more zeros between two numbers
Then the number can be divided into two categories, one is zero, the other is non-zero
We just need to count the number of two non-zero in the middle of how many 0
No 0 That's no, plus ' 0 '
(Non-zero with Shu this variable statistic, 0 of the quantity with Ling variable statistics)
For the ten readings, one is 15, 16, the other is 115, 1015
We just have to judge if there are no other 0 numbers in front of ten to judge whether it's ' ten ' or ' 10 '.
For the three paragraphs, the four-bit digital processing method for each segment is the same, the units processed (million, million, yuan) either at the end of the non-zero or in
0 end, in these two places all add judgment can

ImportJava.text.DecimalFormat; Public classNumberutil { Public StaticString Tochinese (intNumber ) {String ans=""; String Source=string.valueof (number); returnans; }     Public StaticString Tobig (intnum) {String str[]={"One", "II", "three", "the", "WU", "Lu", "Qi", "ba", "JIU", "ten"}; returnStr[num-1]; }         Public StaticString Test2 (Doublex) {DecimalFormat format=NewDecimalFormat ("#.00"); String Str=Format.format (x);        System.out.println (str); String s[]=str.split ("\ \")); String Temp=""; intLing=0; intShu=0; intPos=0;  for(intJ=0;j<s[0].length (); + +j) {            intNum=s[0].charat (j)-' 0 '; if(num==0) {Ling++; if(ling==s[0].length ()) {temp= "0"; }                Else if(S[0].length ()-j-1==4){                    if(shu==1&& (S[0].length ()-pos-1) >=5&& (S[0].length ()-pos-1) <=7) {Temp+ = "million"; }                }                Else if(S[0].length ()-j-1==8){                    if(shu==1&& (S[0].length ()-pos-1) >=9&& (S[0].length ()-pos-1) <=11) {Temp+ = "billion"; }                }            }            Else{Shu++; intFlag=0; if(shu==1) {Ling=0; POS=J; }                if(shu==2) {flag=1; if(ling>0) {Temp+ = "0"; } Shu=1; POS=J; Ling=0; }                if(S[0].length ()-j-1==11) {Temp+=tobig (num) + "thousand"; }                Else if(S[0].length ()-j-1==10) {Temp+=tobig (num) + "hundred"; }                Else if(S[0].length ()-j-1==9){                    if(num==1&&flag!=1) Temp+ = "Ten"; ElseTemp+=tobig (num) + "Ten"; }                Else if(S[0].length ()-j-1==8) {Temp+=tobig (num) + "billion"; }                Else if(S[0].length ()-j-1==7) {Temp+=tobig (num) + "thousand"; }                Else if(S[0].length ()-j-1==6) {Temp+=tobig (num) + "hundred"; }                Else if(S[0].length ()-j-1==5){                    if(num==1&&flag!=1) Temp+ = "Ten"; ElseTemp+=tobig (num) + "Ten"; }                Else if(S[0].length ()-j-1==4) {Temp+=tobig (num) + "million"; }                Else if(S[0].length ()-j-1==3) {Temp+=tobig (num) + "thousand"; }                Else if(S[0].length ()-j-1==2) {Temp+=tobig (num) + "hundred"; }                Else if(S[0].length ()-j-1==1){                    if(num==1&&flag!=1) Temp+ = "Ten"; ElseTemp+=tobig (num) + "Ten"; }                Else{Temp+=tobig (num); }            }    //System.out.println (temp);} temp+ = "Yuan";  for(intJ=0;j<s[1].length (); + +j) {            intNum=s[1].charat (j)-' 0 '; if(j==0){                if(num!=0) Temp+=tobig (num) + "Corner"; Else if(Num==0&&1<s[1].length () &&s[1].charat (1)! = ' 0 ') {Temp+ = "0"; }            }            Else if(j==1){                if(num!=0) Temp+=tobig (num) + "min";        }} System.out.println (temp); returntemp;}  Public Static voidMain (string[] args) {Test2 (800230001.23); }}

The amount of Java Arabic numerals is converted into Chinese capital amount

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.