浮点数转成人民币读法字符串的程序错误
publicclassRmb{privateString[]hanArr={"零","壹","贰","叁","肆","伍","陆","柒","捌","玖"};privat...
public class Rmb
{
private String[] hanArr={"零","壹","贰","叁","肆","伍","陆","柒","捌","玖"};
private String[] unitArr={"仟","佰","拾","元","角","分"};
private String toHanStr(double num)
{
long zheng=(long) num;
long xiao=Math.round((num-zheng)*100);
double num2=(zheng)*100+xiao;
String numstr=String.valueOf(num2);
String result="";
int numlen=numstr.length();
for(int i=0;i<numlen;i++)
{
int num3=numstr.charAt(i)-48;
if(i!=numlen-1&&num3!=0)
{
result+=hanArr[num3]+unitArr[num3-2-i];
}
else
{
if(hanArr[num3]!="零")
{
result+=hanArr[num3];
}
}
}
return result;
}
编译通过了,但是的不出结果提示:Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: -1
拜托大家帮个忙看看,先谢谢了 展开
{
private String[] hanArr={"零","壹","贰","叁","肆","伍","陆","柒","捌","玖"};
private String[] unitArr={"仟","佰","拾","元","角","分"};
private String toHanStr(double num)
{
long zheng=(long) num;
long xiao=Math.round((num-zheng)*100);
double num2=(zheng)*100+xiao;
String numstr=String.valueOf(num2);
String result="";
int numlen=numstr.length();
for(int i=0;i<numlen;i++)
{
int num3=numstr.charAt(i)-48;
if(i!=numlen-1&&num3!=0)
{
result+=hanArr[num3]+unitArr[num3-2-i];
}
else
{
if(hanArr[num3]!="零")
{
result+=hanArr[num3];
}
}
}
return result;
}
编译通过了,但是的不出结果提示:Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: -1
拜托大家帮个忙看看,先谢谢了 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询