java math round
时间: 2023-08-24 17:06:13 浏览: 150
详解Java中Math.round()的取整规则
The `Math.round()` method in Java is used to round a float or double value to the nearest integer.
Syntax:
```java
public static long round(double value)
public static int round(float value)
```
Example:
```java
double num1 = 5.5;
double num2 = 5.2;
double num3 = 5.8;
System.out.println(Math.round(num1)); // Output: 6
System.out.println(Math.round(num2)); // Output: 5
System.out.println(Math.round(num3)); // Output: 6
```
In the above example, we have used the `Math.round()` method to round the double values to the nearest integer. The output shows the rounded values.
阅读全文