/*** 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