Results 1 to 2 of 2
  1. #1
    Valeriano is offline Member
    Join Date
    May 2007
    Posts
    10
    Rep Power
    0

    Default How to round a double?

    I have a method that prints out two doubles after a series of mathematical operations. I need the doubles to be displayed with two decimal places. I don't need to do anything with the rounded doubles, I just need to print them out. How can i do that?

  2. #2
    Hasan is offline Member
    Join Date
    May 2007
    Posts
    11
    Rep Power
    0

    Default

    You can use DecimalFormat class for printing.

    Java Code:
    double x = 1.20136;
    DecimalFormat f = new DecimalFormat("#.##");
    f.format(x);

Similar Threads

  1. round to two decimal places
    By javaMike in forum New To Java
    Replies: 3
    Last Post: 12-24-2011, 03:01 AM
  2. Calculating sin of a double value
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 01-13-2008, 09:13 PM
  3. transforming double to int
    By AlejandroPenton in forum New To Java
    Replies: 2
    Last Post: 12-11-2007, 02:34 AM
  4. Getting smallest possible Double value
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 12-06-2007, 03:15 PM
  5. Replies: 1
    Last Post: 05-20-2007, 12:19 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
  •