Diplaying floating point values

Thread Solved

Join Date: Oct 2007
Posts: 60
Reputation: Grub is an unknown quantity at this point 
Solved Threads: 0
Grub Grub is offline Offline
Junior Poster in Training

Diplaying floating point values

 
0
  #1
Nov 22nd, 2007
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.
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 4,438
Reputation: Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of 
Solved Threads: 510
Moderator
Featured Poster
Ezzaral's Avatar
Ezzaral Ezzaral is offline Offline
Industrious Poster

Re: Diplaying floating point values

 
0
  #2
Nov 22nd, 2007
You'll need to use a formatter like DecimalFormat or String.format().
  1. float value = 0.60f;
  2. DecimalFormat df = new DecimalFormat("0.00");
  3. String formattedValue = df.format(value);
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 8
Reputation: arumugam4all is an unknown quantity at this point 
Solved Threads: 1
arumugam4all arumugam4all is offline Offline
Newbie Poster

Re: Diplaying floating point values

 
0
  #3
Nov 22nd, 2007
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));
Arumugam
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 60
Reputation: Grub is an unknown quantity at this point 
Solved Threads: 0
Grub Grub is offline Offline
Junior Poster in Training

Re: Diplaying floating point values

 
0
  #4
Nov 23rd, 2007
Many thanks. This thread is closed.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC