private static final char[] data = new char[]{
'零','壹','贰','叁','肆','伍','陆','柒','捌','玖'
};
private static final char[] units = new char[]{
'整','圆','拾','佰','仟','万','拾','佰','仟','亿','拾','佰','仟'
};
public static void main(String[] args)
{
convert(101000001010L);
}
public static String convert(long money )
{
StringBuffer sbf = new StringBuffer();
int unit = 0;
sbf.insert(unit);
while(money!=0)
{
// sbf.insert(0,units[unit++]);
// System.out.println(units[unit++]);
System.out.println(sbf.insert(0,units[++unit]));
int number = money%10;
private static final char[] data = new char[]{
'零','壹','贰','叁','肆','伍','陆','柒','捌','玖'
};
private static final char[] units = new char[]{
'整','圆','拾','佰','仟','万','拾','佰','仟','亿','拾','佰','仟'
};
public static void main(String[] args){
convert(101000001010L);
}
public static String convert(long money )
{
StringBuffer sbf = new StringBuffer();
int unit = 0;
sbf.insert(0,unit);
while(money!=0)
{
// sbf.insert(0,units[unit++]);
// System.out.println(units[unit++]);
System.out.println(sbf.insert(0,units[++unit]));
long number = money % 10;
int number2 = (int)number;
System.out.println(sbf.insert(0, data[number2]));
money /= 10;
}
return sbf.toString();
}
} 作者: 周兴华 时间: 2012-9-1 21:48 楼主的程序有两个错误:
1、sbf.insert(unit);这句应改为 sbf.insert(0,units[0]);
2、int number = money%10;应改为int number = (int) (money%10);
因为int number = money%10; //money是long型数据,用long型数据赋值给number是无法通过编译的作者: 王桂丽 时间: 2012-9-1 23:04
此问题已解决