Import Java.util.HashMap;
Import Java.util.Map;
public class Figureandchinese2util {
That caches all numbers.
private static Map<character, character> Map = new Hashmap<character, character> (
10);
static {
Map.put (' 1 ', ' one ');
Map.put (' 2 ', ' II ');
Map.put (' 3 ', ' three ');
Map.put (' 4 ', ' Restaurant ');
Map.put (' 5 ', ' Wu ');
Map.put (' 6 ', ' land ');
Map.put (' 7 ', ' Qi ');
Map.put (' 8 ', ' BA ');
Map.put (' 9 ', ' JIU ');
Map.put (' 0 ', ' 0 ');
}
Static char[] mode = new char[] {' Pick ', ' bai ', ' thousand '};
public static void M (String sb) {
StringBuffer SBF = new StringBuffer ();
string[] sp = Sb.split ("\.");
if (sp.length = = 2) {
M0 (Sp[0], 0, SBF);
Sbf.append (M2 (sp[1));
} else
M0 (SB, 0, SBF);
Sbf.append ("whole");
System.out.println (SBF);
}
/***
* Cutting string
*
* @param SB
*/
public static void M0 (String sb, int type, StringBuffer SBF) {
int len = Sb.length ();
int b = 0;
type++;
if (Len >= 4) {
b = len-4;
Sbf.insert (0, M1 (sb.substring (b), type));
M0 (sb.substring (0, b), type, SBF);
else if (len > 0)
Sbf.insert (0, M1 (SB, type));
if (' 0 ' = Sbf.charat (0))
Sbf.deletecharat (0);
}
/***
* Processing
*
* @param SB
*/
public static StringBuffer M1 (String sb, int type) {
StringBuffer SBF = new StringBuffer (SB);
Switch (type) {
Case 1:
Sbf.append ("Round");
Break
Case 2:
Sbf.append ("million");
Break
Case 3:
Sbf.append ("billion");
Break
Default
Break
}
Start assigning values
int b = 0;
char t = 0;
for (int i = Sbf.length ()-2; I >= 0; i--) {
t = Sbf.charat (i);
Sbf.setcharat (i, Map.get (t));
if (i!= 0)
Sbf.insert (i, mode[b]);
b++;
}
for (int i = 0; i < sbf.length (); i++) {
t = Sbf.charat (i);
if (t = = ' 0 ') {
t = Sbf.charat (i + 1);
if (' Round '!= t && ' million '!= t && ' billion '!= t)
Sbf.deletecharat (i + 1);
Else
Sbf.deletecharat (i);
if (i!= 0)
if (Sbf.charat (i-1) = = ' 0 ') {
Sbf.deletecharat (i-1);
i--;
}
}
}
if (sbf.length () = = 1) {
if (' Round '!= sbf.charat (0))
Sbf.setlength (0);
}
return SBF;
}
public static StringBuffer m2 (String de) {
if (De.length () > 2)
de = de.substring (0, 2);
de = De.replacefirst ("00", "");
stringbuffer sb = new StringBuffer (DE);
if (sb.length () > 0) {
if (Sb.charat (Sb.length ()-1) = = ' 0 ')
& Nbsp; sb.deletecharat (Sb.length ()-1);
sb.setcharat (0, Map.get (Sb.charat (0)));
switch (Sb.length ()) {
case 1:
sb.append (corner ");
break;
case 2:
sb.setcharat (1, Map.get (Sb.charat (1));
if (Sb.charat (0)!= ' 0 ')
sb.insert (1, ' Corner ');
sb.append ("min");
break;
default:
break;
}
return sb;
.}
public static void Main (string[] args) {
String s = "4444444441.23";
String S1 = "1";
String s2 = "1000000000.01";
String s3 = "101010002.11";
m (s);
M (S1);
m (S2);
M (S3);
}
}