Round of help

• 10-08-2011, 04:57 AM
micolord
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...

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.
*/
}
}

• 10-08-2011, 05:15 AM
micolord
Re: Round of help
Giving me simple example would be great!
• 10-08-2011, 05:39 AM
jammas615
Re: Round of help
In the math Class there are rounding functions. Take a read: Math (Java 2 Platform SE v1.4.2)
• 10-08-2011, 05:45 AM
micolord
Re: Round of help
Quote:

Originally Posted by jammas615
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.
• 10-08-2011, 05:52 AM
jammas615
Re: Round of help
Well if you took the initiative to read the link it showed you the function you need.
But,
Code:

double num = 1.99;
int rounded;

rounded = (int)(Math.round(num + 0.5);

If you read i did EXACTLY what the example did.
• 10-08-2011, 05:56 AM
micolord
Re: Round of help
Thanks :D for helping! :) +1 rep