Results 1 to 4 of 4
  1. #1
    Hype is offline Member
    Join Date
    Jan 2011
    Posts
    6
    Rep Power
    0

    Default Using math.round

    Hi,

    I'm dividing two double numbers 7.0 and 9.0 (which is 0.777777778) and I need to round off that answer using Math.round so the answer is 1. How would I code that?

  2. #2
    Vase is offline Member
    Join Date
    Jan 2011
    Location
    Gainesville, FL
    Posts
    45
    Rep Power
    0

    Default

    Java Code:
    int result = (int)Math.round(7.0 / 9.0);
    ?

  3. #3
    tanjo3 is offline Member
    Join Date
    Jan 2011
    Posts
    9
    Rep Power
    0

    Default

    Java Code:
    double a, b, ans;
    
    ans = Math.ceil(a / b);
    It'll always round up though.

  4. #4
    Hype is offline Member
    Join Date
    Jan 2011
    Posts
    6
    Rep Power
    0

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. Create Math.sin without math.sin
    By vudoo in forum New To Java
    Replies: 11
    Last Post: 12-07-2010, 07:23 AM
  3. going round and round in class..
    By sonny in forum New To Java
    Replies: 52
    Last Post: 04-02-2010, 11:56 AM
  4. stopping second time round
    By silverspoon34 in forum New To Java
    Replies: 0
    Last Post: 11-20-2009, 03:04 PM
  5. How to round a double?
    By Valeriano in forum New To Java
    Replies: 1
    Last Post: 05-31-2007, 04: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
  •