User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Java section within the Software Development category of DaniWeb, a massive community of 455,970 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,773 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Java advertiser: Lunarpages Java Web Hosting
Views: 707 | Replies: 3 | Solved
Reply
Join Date: Oct 2007
Posts: 37
Reputation: Grub is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
Grub Grub is offline Offline
Light Poster

Diplaying floating point values

  #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.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: May 2007
Location: USA
Posts: 3,076
Reputation: Ezzaral is a splendid one to behold Ezzaral is a splendid one to behold Ezzaral is a splendid one to behold Ezzaral is a splendid one to behold Ezzaral is a splendid one to behold Ezzaral is a splendid one to behold Ezzaral is a splendid one to behold 
Rep Power: 15
Solved Threads: 306
Featured Poster
Ezzaral's Avatar
Ezzaral Ezzaral is offline Offline
Posting Sensei

Re: Diplaying floating point values

  #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  
Join Date: Nov 2007
Location: Coimbatore-India
Posts: 8
Reputation: arumugam4all is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 1
arumugam4all arumugam4all is offline Offline
Newbie Poster

Solution Re: Diplaying floating point values

  #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  
Join Date: Oct 2007
Posts: 37
Reputation: Grub is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
Grub Grub is offline Offline
Light Poster

Re: Diplaying floating point values

  #4  
Nov 23rd, 2007
Many thanks. This thread is closed.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb Java Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the Java Forum

All times are GMT -4. The time now is 9:12 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC