package com.test;
import junit.framework.TestCase;
public class TestLetter extends TestCase{
private static final char RMB[] = {'拾','百','千','万','拾','百','千','亿'};
private static final char NUMBER[] = {'零','一','二','三','四','五','六','七','八','九'};
public void testChange() throws Exception {
int n = 132222113;
System.out.println(changeRMBToChinese(n));
}
public void test_letter() throws Exception {
String s = "我ABC汉DEF";
System.out.println(splitLetter(s, 6));
}
private String changeRMBToChinese(Integer n){
int length = String.valueOf(n).length();
System.out.println(length);
StringBuffer sb = new StringBuffer();
for(int i=length-1;i>=0;i--){
int num = n/Double.valueOf(Math.pow(10, i)).intValue();
n = n % Double.valueOf(Math.pow(10, i)).intValue();
System.out.println("除数:"+Double.valueOf(Math.pow(10, i)).intValue());
System.out.println("num:"+num);
sb.append(NUMBER[num]);
if(i>0 && !"零".equals(NUMBER[num]))
sb.append(RMB[i-1]);
}
return sb.append("元").toString();
}
private String splitLetter(String str,int bytesize){
int j = 0;
StringBuffer sb = new StringBuffer();
char[] cs = str.toCharArray();
for(int i=0;i<cs.length;i++){
if(isChinese(cs[i])){
j = j + 2;
}else{
j = j + 1;
}
if(j<=bytesize){
sb.append(cs[i]);
}else{
break;
}
}
return sb.toString();
}
private boolean isChinese(char c){
return (new StringBuffer().append(c).toString().getBytes().length)==1?false:true;
}
}
?