我在使用DecimalFormat
进行回归后打印输出系数时遇到问题。使用DecimalFormat的问题
以下是面临问题的部分代码;
DecimalFormat twoDForm = new DecimalFormat("0.00");
private double s(double d){
return Double.valueOf(twoDForm.format(d));
}
这里是eclipse中的错误信息;
Exception in thread "main" java.lang.NumberFormatException: For input string: "0,16"
at sun.misc.FloatingDecimal.readJavaFormatString(Unknown Source)
at java.lang.Double.valueOf(Unknown Source)
at model.ARF2.s(ARF2.java:126)
at model.ARF2.printBestModel(ARF2.java:114)
at testing.testclass3.bestForecastingModel(testclass3.java:69)
at testing.testclass3.main(testclass3.java:36)
请让我知道,如果任何人有任何关于如何修复代码surgestions。我的系数需要两位小数。
谢谢
拉尔斯
点是否正确?不应该是'DecimalFormat twoDForm = new DecimalFormat(“0,00”);'?我现在不记得了。 – 2010-09-17 13:21:53
什么是方法's'的输入? – dogbane 2010-09-17 13:22:26
代码是错误的,但正确的答案取决于你想要做什么。你想打印两位小数,截断其余部分(有效舍入)吗?或者当你想要使用一个特定的舍入方法时,如果有更多的数字比你有小数位打印? – Jeff 2010-09-17 13:33:46