Diplaying floating point values
Hi, I am trying to display my floating point values as money in a machine. Now When I display the value 0.60, the zero is omitted from the end and as such is displayed as 0.6. I need to display it as 0.60.
Many thanks in advance.
Grub
Junior Poster in Training
60 posts since Oct 2007
Reputation Points: 14
Solved Threads: 0
You'll need to use a formatter like DecimalFormat or String.format().
float value = 0.60f;
DecimalFormat df = new DecimalFormat("0.00");
String formattedValue = df.format(value);
Ezzaral
Posting Genius
15,985 posts since May 2007
Reputation Points: 3,250
Solved Threads: 847
Many thanks. This thread is closed.
Grub
Junior Poster in Training
60 posts since Oct 2007
Reputation Points: 14
Solved Threads: 0