📅  最后修改于: 2023-12-03 15:02:53.019000             🧑  作者: Mango
The Math.round()
method in Java is a built-in function that rounds a specified expression or value to the nearest integer.
public static long round(double value)
where value
specifies the value to be rounded.
The Math.round()
method returns the long
value representing the rounded integer.
double num = 3.14159;
long roundedValue = Math.round(num);
System.out.println("Rounded value of " + num + " is " + roundedValue);
Output:
Rounded value of 3.14159 is 3
float
data type, but the return type will still be long
.Math.round()
method uses the RoundingMode.HALF_UP
mode as its default rounding mode.So, this was a brief introduction to the Math.round()
method in Java, which is very useful for mathematical calculations in Java programs.