Arabic numerals to Chinese (kanji) numbers

Source: Internet
Author: User

/*** Number Tool type *@authorRubekid **/ Public classNumberutils {Private Final StaticString[] Group_units = {"", "Million", "billion", "mega"}; Private Final StaticString[] Base_units = {"", "ten", "Hundred", "thousand" }; Private Final Static Char[] simplified_numberic = {' 0 ', ' one ', ' two ', ' three ', ' four ', ' five ', ' six ', ' seven ', ' eight ', ' nine ' }; Private Final Static Char[] traditional_numberic = {' 0 ', ' one ', ' II ', ' three ', ' establishments ', ' Wu ', ' Lu ', ' qi ', ' ba ', ' JIU ' }; /*** converted to Chinese numerals *@paramNumber Value *@paramistraditional to Traditional *@return     */     Public StaticString Tochinese (LongNumberBooleanistraditional) {        Char[] Numberic = istraditional?Traditional_numberic:simplified_numberic; String Str=string.valueof (number); Char[] numbers =Str.tochararray (); intLen =str.length (); //statistics of 0 consecutive occurrences        intZerocount = 0; StringBuffer StringBuffer=NewStringBuffer ();  for(inti = 0; I<len; i++){            intValue =Integer.parseint (string.valueof (numbers[i)); intindex = len-i-1; //Subscript in a group            int_index = index% 4; if(Value = = 0) {Zerocount++; if(_index = = 0 && zerocount < 4) | | (index% 8 = = 0 && Zerocount < 8) {stringbuffer.append (getgroupunit (index)); Zerocount= 0; }            }            Else{                if(Zerocount > 0) {stringbuffer.append (numberic[0]); }                if(_index = = 0) {stringbuffer.append (Numberic[value]+ Base_units[_index] +getgroupunit (index)); Zerocount= 0; }                Else{                    //adjust to "10" does not need to appear "one" such as: 100000 read "100,000" instead of "100,000"                    if(_index = = 1 && i==0 && value== 1) {stringbuffer.append (Base_units[_index]); }                    Else{stringbuffer.append (Numberic[value]+Base_units[_index]); }} Zerocount= 0; }                    }        returnstringbuffer.tostring (); }        /*** converted to Chinese numerals *@paramNumber Value *@return     */     Public StaticString Tochinese (LongNumber ) {        returnTochinese (number,false); }        /*** converted to Chinese numerals *@paramNumber Value *@paramistraditional whether to convert to traditional*/     Public StaticString Tochinese (intNumberBooleanistraditional) {        returnTochinese ((Long) number, istraditional); }            /*** converted to Chinese numerals *@paramNumber Value*/     Public StaticString Tochinese (intNumber ) {        returnTochinese (number,false); }        /*** Get Group units *@paramIndex *@return     */    Private StaticString Getgroupunit (intindex) {String Groupunit= group_units[(INDEX/4)% 2]; if(index% 8 = = 0 && Index > 0) {Groupunit+ = group_units[(INDEX/8) +1]; }        returnGroupunit; }}

Arabic numerals to Chinese (kanji) numbers

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.