Jenn
0
Q:

round function in java

import java.lang.Math; 
double num1 = 74.65;
System.out.println(Math.round(num1));
1
int x = 3.14;

Math.round(x);
//Rounds to nearest int
Math.ceil(x);
//Rounds up to int
Math.floor(x);
//Rounds down to int
1
Math.round(y)
3
double test = 0.01;
// rounds up to the next INTEGER
test = Math.ceil(test);  // 1.0


double test2 = 1.0;
// does not round if decimal is 0
test2 = Math.ceil(test2);  // 1.0
0

New to Communities?

Join the community