Java Math.round(float a)
Syntax
Math.round(float a) has the following syntax.
public static int round(float a)
Example
In the following code shows how to use Math.round(float a) method.
/*ww w .j a v a 2s . co m*/
public class Main {
public static void main(String[] args) {
float x = 1234.1234f;
float y = -1234.123f;
// find the closest int for these floats
System.out.println("Math.round(" + x + ")=" + Math.round(x));
System.out.println("Math.round(" + y + ")=" + Math.round(y));
}
}
The code above generates the following result.