Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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));  
}  

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.

Thank you

Lars

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
268 views
Welcome To Ask or Share your Answers For Others

1 Answer

use:

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...