我不太懂这个 想看看前辈们的 源代码作者: 陈欢 时间: 2012-7-16 18:15
public class ZhuanHuan {
private static final char[] data = new char[]{
'零','一','贰','叁','肆','伍','陆','柒','捌','玖'
};
private static final char[] units = new char[]{
'元','拾','佰','仟','万','拾','佰','仟','亿'
};
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println(
convert(1011));
}
public static String convert(int money)
{
StringBuffer sbf = new StringBuffer();
int unit = 0;
while(money!=0)
{
sbf.insert(0,units[unit++]);
int number = money%10;
sbf.insert(0, data[number]);
money /= 10;
}
return sbf.toString();
}
}
这是我上网看见的结果,可以参考下
package test.format;
import java.text.NumberFormat;
import java.util.HashMap;
public class SimpleMoneyFormat {
public static final String EMPTY = "";
public static final String ZERO = "零";
public static final String ONE = "壹";
public static final String TWO = "贰";
public static final String THREE = "叁";
public static final String FOUR = "肆";
public static final String FIVE = "伍";
public static final String SIX = "陆";
public static final String SEVEN = "柒";
public static final String EIGHT = "捌";
public static final String NINE = "玖";
public static final String TEN = "拾";
public static final String HUNDRED = "佰";
public static final String THOUSAND = "仟";
public static final String TEN_THOUSAND = "万";
public static final String HUNDRED_MILLION = "亿";
public static final String YUAN = "元";
public static final String JIAO = "角";
public static final String FEN = "分";
public static final String DOT = ".";