java异常,format的,不清楚怎么错的
Exceptioninthread"main"java.lang.IllegalArgumentException:CannotformatgivenObjectasaN...
Exception in thread "main" java.lang.IllegalArgumentException: Cannot format given Object as a Number
at java.text.DecimalFormat.format(Unknown Source)
at java.text.Format.format(Unknown Source)
at com.finance.moneyRate.MoneyRate.monthReturn(MoneyRate.java:35)
at com.finance.moneyRate.main.main(main.java:9)
下面是我的一小段代码:
case EQUAL_RATE:
double x = Math.pow((i+1), n);
String sMonthReturn = Double.toString(x*a*i/(x-1));
monthReturn = Double.valueOf(df.format(sMonthReturn));
break;
代码都弄上来长了
//从界面获取的数据
private float I = 0.069f;//年利率
private double a = 100000;//贷款额
private int n = 12;//还期,月
//需要计算的结果
private float i = I/12;//月利率
private double mustReturn = 0;//应还款总和
private double allRate = 0;//应还利息总和
private double monthReturn = 0;//每月应还款
private double monthOriginal = 0;//每月应还本金
private double monthRate = 0;//每月应还利息
private double surplus = 0;//剩余本金
DecimalFormat df=new DecimalFormat("#.00");//取2位小数 展开
at java.text.DecimalFormat.format(Unknown Source)
at java.text.Format.format(Unknown Source)
at com.finance.moneyRate.MoneyRate.monthReturn(MoneyRate.java:35)
at com.finance.moneyRate.main.main(main.java:9)
下面是我的一小段代码:
case EQUAL_RATE:
double x = Math.pow((i+1), n);
String sMonthReturn = Double.toString(x*a*i/(x-1));
monthReturn = Double.valueOf(df.format(sMonthReturn));
break;
代码都弄上来长了
//从界面获取的数据
private float I = 0.069f;//年利率
private double a = 100000;//贷款额
private int n = 12;//还期,月
//需要计算的结果
private float i = I/12;//月利率
private double mustReturn = 0;//应还款总和
private double allRate = 0;//应还利息总和
private double monthReturn = 0;//每月应还款
private double monthOriginal = 0;//每月应还本金
private double monthRate = 0;//每月应还利息
private double surplus = 0;//剩余本金
DecimalFormat df=new DecimalFormat("#.00");//取2位小数 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询