Results 1 to 6 of 6

Thread: Round of help

  1. #1
    micolord is offline Member
    Join Date
    Sep 2011
    Location
    Philippines
    Posts
    41
    Rep Power
    0

    Default Round of help

    I'm in the making of a GRADINGSYSTEM for my project in copro1 and my problem is I don't know how to round off numbers...

    Java Code:
    public class roundoff
    {
    public static void main(String [] args)
    {
    double num = 1.99;
    /*
    I want to round off num to 2 just like in math when the first numbers in the dot left side is 5 
    above then the number right side of dot is added an extra one and the 
    left side of the dot is removed. 2.
    */
    }
    }
    Last edited by micolord; 10-08-2011 at 05:08 AM.

  2. #2
    micolord is offline Member
    Join Date
    Sep 2011
    Location
    Philippines
    Posts
    41
    Rep Power
    0

    Default Re: Round of help

    Giving me simple example would be great!

  3. #3
    jammas615 is offline Senior Member
    Join Date
    Jul 2011
    Location
    Melbourne, Victoria, Australia
    Posts
    155
    Rep Power
    4

    Default Re: Round of help

    In the math Class there are rounding functions. Take a read: Math (Java 2 Platform SE v1.4.2)

  4. #4
    micolord is offline Member
    Join Date
    Sep 2011
    Location
    Philippines
    Posts
    41
    Rep Power
    0

    Default Re: Round of help

    Quote Originally Posted by jammas615 View Post
    In the math Class there are rounding functions. Take a read: Math (Java 2 Platform SE v1.4.2)
    will you just please give me a little example according to what I have explain I need and I'll study it myself.

  5. #5
    jammas615 is offline Senior Member
    Join Date
    Jul 2011
    Location
    Melbourne, Victoria, Australia
    Posts
    155
    Rep Power
    4

    Default Re: Round of help

    Well if you took the initiative to read the link it showed you the function you need.
    But,
    Java Code:
    double num = 1.99;
    int rounded;
    
    rounded = (int)(Math.round(num + 0.5);
    If you read i did EXACTLY what the example did.

  6. #6
    micolord is offline Member
    Join Date
    Sep 2011
    Location
    Philippines
    Posts
    41
    Rep Power
    0

Similar Threads

  1. Using math.round
    By Hype in forum New To Java
    Replies: 3
    Last Post: 01-30-2011, 11:57 PM
  2. going round and round in class..
    By sonny in forum New To Java
    Replies: 52
    Last Post: 04-02-2010, 10:56 AM
  3. How to Draw Round Rectangles in SWT
    By Java Tip in forum SWT Tips
    Replies: 0
    Last Post: 06-28-2008, 09:25 PM
  4. 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
  •