使用DecimalFormat的问题 [英] Problems using DecimalFormat

查看:349
本文介绍了使用DecimalFormat的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我要在回归后打印出系数时,我在使用 DecimalFormat 时遇到了问题。

I am having problems using DecimalFormat when I am going to print out coefficients after a regression.

这里是代码中遇到问题的部分;

Here is the part of the code that is facing problems;

DecimalFormat twoDForm = new DecimalFormat("0.00");   
private double s(double d){  
    return Double.valueOf(twoDForm.format(d));  
}  

这里是eclipse中的错误信息;

and here is the error message in 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)  

如果有人对如何修复代码有任何激增,请告诉我。我想要系数上的两位小数。

Please let me know if anyone has any surgestions on how to fix the code. I want two decimals on my coefficients.

谢谢

Lars

推荐答案

使用:

    DecimalFormat twoDForm = new DecimalFormat("#.##");
    DecimalFormatSymbols dfs = new DecimalFormatSymbols();
    dfs.setDecimalSeparator('.');
    twoDForm.setDecimalFormatSymbols(dfs);

这篇关于使用DecimalFormat的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆