944,172 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Marked Solved
  • Views: 1878
  • Java RSS
Nov 22nd, 2007
0

Diplaying floating point values

Expand Post »
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.
Reputation Points: 14
Solved Threads: 0
Junior Poster in Training
Grub is offline Offline
60 posts
since Oct 2007
Nov 22nd, 2007
0

Re: Diplaying floating point values

You'll need to use a formatter like DecimalFormat or String.format().
java Syntax (Toggle Plain Text)
  1. float value = 0.60f;
  2. DecimalFormat df = new DecimalFormat("0.00");
  3. String formattedValue = df.format(value);
Moderator
Featured Poster
Reputation Points: 3239
Solved Threads: 839
Posting Genius
Ezzaral is offline Offline
6,761 posts
since May 2007
Nov 22nd, 2007
0

Re: Diplaying floating point values

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));
Reputation Points: 10
Solved Threads: 1
Newbie Poster
arumugam4all is offline Offline
8 posts
since Nov 2007
Nov 23rd, 2007
0

Re: Diplaying floating point values

Many thanks. This thread is closed.
Reputation Points: 14
Solved Threads: 0
Junior Poster in Training
Grub is offline Offline
60 posts
since Oct 2007

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: map ResultSet to objects
Next Thread in Java Forum Timeline: Query about static nested classes





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC