Hello All.
I tried this format:
but I am not getting 2 decimal places that i need.Code:double homePrice;
String.format("%.2f", homePrice);
ex. I get $100000.0 Even if I type 100 I get 100.0 (?)
Thanks In Advance
Printable View
Hello All.
I tried this format:
but I am not getting 2 decimal places that i need.Code:double homePrice;
String.format("%.2f", homePrice);
ex. I get $100000.0 Even if I type 100 I get 100.0 (?)
Thanks In Advance
How exactly are you executing the code?
Code:double homePrice = 100;
String x = String.format("%.2f", homePrice);
System.out.println(x);
That's my code/output.Code:run:
100.00
BUILD SUCCESSFUL (total time: 1 second)
Could this "homePrice =" statement have anything to do with the output formatting not coming out as 2 decimals?:confused: :confused:
I tried your suggestion Zack.
Code:homePrice = Double.parseDouble(inputStr);
String x = String.format("%.2f", homePrice);
How are you now outputting x? As long as homePrice has a value it should force the two decimal places.
Continued from http://www.java-forums.org/new-java/...gue-boxes.html
db
lala I showed you this in that thread Darryl.Burke is linking to