Results 1 to 3 of 3
  1. #1
    sakthivel123 is offline Member
    Join Date
    Jul 2008
    Rep Power

    Default Double Value problem

    Hi all,

    I have a Double with this value 136546.215454 and I want to convert it to: 136546.21 How can I do that (Only 2 decimals after ".")


  2. #2
    Nicholas Jordan's Avatar
    Nicholas Jordan is offline Senior Member
    Join Date
    Jun 2008
    Rep Power


    There is a NumberFormat somewhere, I can help you find it.

    google: "java NumberFormat"
    Introduction to Programming Using Java.
    Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor

  3. #3
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Eastern Florida
    Rep Power


    Is it the display of the Double you want to change(ie when you print it) or the value of the Double? That is you want the value of the Double to be:136546.21000000 ie all zeros after the .21
    A way might be to multiple the value by 100, convert to long and then convert to Double and divide by 100. For example:
    Java Code:
         double d = 1234.21345666;
         d = d * 100.0;
         long dI = (long)d;
         double e = ((double) dI)/ 100.0;
         System.out.println("d=" + d + ", e=" + e); //d=123421.34566600001, e=1234.21

Similar Threads

  1. Double Buffering problem
    By aprenz in forum Java Applets
    Replies: 0
    Last Post: 05-28-2008, 04:26 AM
  2. Calculating sin of a double value
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 01-13-2008, 08:13 PM
  3. transforming double to int
    By AlejandroPenton in forum New To Java
    Replies: 2
    Last Post: 12-11-2007, 01:34 AM
  4. Getting smallest possible Double value
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 12-06-2007, 02:15 PM
  5. How to round a double?
    By Valeriano in forum New To Java
    Replies: 1
    Last Post: 05-31-2007, 03:50 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts