954,219 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

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
Moderator
15,985 posts since May 2007
Reputation Points: 3,250
Solved Threads: 847
 

I think this will help you..
// To display the Decimal
float amt=0.60f;

NumberFormat formatter;
formatter=NumberFormat.getIntegerInstance();
formatter.setMinimumFractionDigits(2);

System.out.println(formatter.format(amt));

arumugam4all
Newbie Poster
8 posts since Nov 2007
Reputation Points: 10
Solved Threads: 1
 

Many thanks. This thread is closed.

Grub
Junior Poster in Training
60 posts since Oct 2007
Reputation Points: 14
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You