public String ChineseMoney(String money) {
String text = transChineseMoney1(money) + transChineseMoney2(money);
Pattern p = Pattern.compile("零分", Pattern.CASE_INSENSITIVE);
Matcher m = p.matcher(text);
return text;
}
public String transChineseMoney1(String s) {
String ss = s;
String tmpnewchar = "";
String[] part = ss.split("\\.");
if (part[0].length() > 10) {
return "";
}
for (int i = 0; i < part[0].length(); i++) {
char perchar = part[0].charAt(i);
if (perchar == '0') {
tmpnewchar = tmpnewchar + "零";
}
if (perchar == '1') {
tmpnewchar = tmpnewchar + "壹";
}
if (perchar == '2') {
tmpnewchar = tmpnewchar + "贰";
}
if (perchar == '3') {
tmpnewchar = tmpnewchar + "叁";
}
if (perchar == '4') {
tmpnewchar = tmpnewchar + "肆";
}
if (perchar == '5') {
tmpnewchar = tmpnewchar + "伍";
}
if (perchar == '6') {
tmpnewchar = tmpnewchar + "陆";
}
if (perchar == '7') {
tmpnewchar = tmpnewchar + "柒";
}
if (perchar == '8') {
tmpnewchar = tmpnewchar + "捌";
}
if (perchar == '9') {
tmpnewchar = tmpnewchar + "玖";
}
int j = part[0].length() - i - 1;
if (j == 0) {
tmpnewchar = tmpnewchar + "圆";
}
if (j == 1 && perchar != '0') {
tmpnewchar = tmpnewchar + "拾";
}
if (j == 2 && perchar != '0') {
tmpnewchar = tmpnewchar + "佰";
}
if (j == 3 && perchar != '0') {
tmpnewchar = tmpnewchar + "仟";
}
if (j == 4 && perchar != '0') {
tmpnewchar = tmpnewchar + "万";
}
if (j == 5 && perchar != '0') {
tmpnewchar = tmpnewchar + "拾";
}
if (j == 6 && perchar != '0') {
tmpnewchar = tmpnewchar + "佰";
}
if (j == 7 && perchar != '0') {
tmpnewchar = tmpnewchar + "仟";
}
if (j == 8 && perchar != '0') {
tmpnewchar = tmpnewchar + "亿";
}
if (j == 9 && perchar != '0') {
tmpnewchar = tmpnewchar + "拾";
}
}
return tmpnewchar;
}
public String transChineseMoney2(String s) {
String ss = s;
String tmpnewchar1 = "";
String[] part = ss.split("\\.");
if (ss.indexOf(".") != -1) {
if (part[1].length() > 2) {
part[1] = part[1].substring(0, 2);
}
for (int i = 0; i < part[1].length(); i++) {
char perchar = part[1].charAt(i);
if (perchar == '0') {
tmpnewchar1 = tmpnewchar1 + "零";
}
if (perchar == '1') {
tmpnewchar1 = tmpnewchar1 + "壹";
}
if (perchar == '2') {
tmpnewchar1 = tmpnewchar1 + "贰";
}
if (perchar == '3') {
tmpnewchar1 = tmpnewchar1 + "叁";
}
if (perchar == '4') {
tmpnewchar1 = tmpnewchar1 + "肆";
}
if (perchar == '5') {
tmpnewchar1 = tmpnewchar1 + "伍";
}
if (perchar == '6') {
tmpnewchar1 = tmpnewchar1 + "陆";
}
if (perchar == '7') {
tmpnewchar1 = tmpnewchar1 + "柒";
}
if (perchar == '8') {
tmpnewchar1 = tmpnewchar1 + "捌";
}
if (perchar == '9') {
tmpnewchar1 = tmpnewchar1 + "玖";
}
if (i == 0 && perchar != 0) {
tmpnewchar1 = tmpnewchar1 + "角";
}
if (i == 1 && perchar != 0) {
tmpnewchar1 = tmpnewchar1 + "分";
}
}
}
return tmpnewchar1;
}
@Test
public void testMoney() throws Exception {
String str = ChineseMoney("759656.56");
System.out.println("str = " + str);
}
