1 PackageSFBC;2 3 ImportJava.text.DecimalFormat;4 ImportJava.util.HashMap;5 ImportJava.util.Map;6 /**7 * Amount conversion, the amount of Arabic numerals converted into Chinese traditional output. 8 * @authorTrfizeng9 *Ten */ One Public classFORMATEMONEYCN { A //uppercase Chinese characters corresponding to Arabic numerals - Public Static Finalmap<string, string> number_cn =NewHashmap<string, string>(); - //Uppercase Units the Public Static Finalstring[] Unit_up_cn =NewString[] {"Circle", "Pick", "Bai", -"Thousand", "Million", "Pick", "Bai", "Qian", "billion", "Pick Up", "Bai", "Qian" }; - //uppercase units after the decimal point - Public Static Finalstring[] Unit_down_cn =NewString[] {"Angle", "min" }; + //symbols - Public Static FinalMap<string, string> single =NewHashmap<string, string>(); + Static { ANumber_cn.put (0 + "", "0"); atNumber_cn.put (1 + "", "one"); -Number_cn.put (2 + "", "Ii."); -Number_cn.put (3 + "", "three"); -Number_cn.put (4 + "", "Restaurant")); -Number_cn.put (5 + "", "WU"); -Number_cn.put (6 + "", "Lu")); inNumber_cn.put (7 + "", "Qi"); -Number_cn.put (8 + "", "BA"); toNumber_cn.put (9 + "", "JIU"); + -Single.put ("-", "negative"); theSingle.put ("", "" "); *Single.put ("+", "" "); $ }Panax Notoginseng - Public StaticString FORMATENUMBERTOCN (DoubleNumber ) { theString Tformatenumber =formatenumber (number); + returnNUMBERTOCN (tformatenumber); A } the + //formatted data is 2 digits after the decimal point - Public StaticString Formatenumber (DoubleNumber ) { $DecimalFormat DF =NewDecimalFormat ("#.##"); $ returnDf.format (number); - } - the //Convert Arab data into Chinese capital - Public Staticstring NUMBERTOCN (string number) {WuyiStringBuffer SB =NewStringBuffer (); the //get the decimal point position - intPoint = Number.indexof (".")); Wu //Extracting Symbols -String single = Single About. Get (number.substring (0, Number.indexof ("-") + 1)); $ //unsigned numbers -Number = Number.substring (Number.indexof ("-") + 1); -Point = Number.indexof (".")); - //Integer Part A Char[] Upnumber = point > 0? Number.substring (0, point). ToCharArray () + : Number.tochararray (); the //used to control the occurrence of multiple zeros in succession - CharTupnumber = ' '; $ for(inti = upnumber.length; i > 0; i--) { the //uppercase Chinese characters corresponding to Arabic numerals theString TN = Tupnumber = = ' 0 ' && upnumber[upnumber.length-i] = = Tupnumber? "" the: Number_cn.get (Upnumber[upnumber.length-i] + ""); the if(!"". Equals (TN)) { - //if it's 0, there's no unit behind . inSb.append (TN + ("0". Equals (TN)? "": unit_up_cn[i-1])); the } theTupnumber = Upnumber[upnumber.length-i]; About } the //remove the last 0 of the integer part the if("0". Equals (Sb.substring (Sb.length ()-1))) { theSb.deletecharat (Sb.length ()-1); + } - //If there are decimals the if(Point > 0) {Bayi //number of decimal parts the Char[] Downnumber = number.substring (point + 1). ToCharArray (); the for(inti = 0; i < downnumber.length; i++) { -Sb.append (Number_cn.get (Downnumber[i] + "") -+ (downnumber[i] = = ' 0 '? "": Unit_down_cn[i]); the } the //Remove the beginning of the 0 the if("0". Equals (sb.substring (0, 1))) { theSb.deletecharat (0); - } the}Else { the //no decimal is the whole theSb.append ("whole");94 } the returnSingle +sb.tostring (); the } the 98 Public Static voidMain (string[] args) { About DoubleNumber1 = 600073000.034; - DoubleNumber2 = 600073000.036;101 DoubleNumber3 = 600073000;102System.out.println ("\" "+ Number1 +" \ ":" +FORMATENUMBERTOCN (Number1));103System.out.println ("\" "+ number2 +" \ ":" +FORMATENUMBERTOCN (number2));104System.out.println ("\" "+ Number3 +" \ ":" +FORMATENUMBERTOCN (Number3)); the }106}
View Code
"6.00073000034E8": Lu Ying Zero seven Wan 0 three points
"6.00073000036E8": Lu Ying Zero seven Wan 0 cents
"6.00073E8": Lu Ying Zero Qi Wan Whole
Amount conversion, the amount of Arabic numerals converted into Chinese traditional output.