Java Math round() 方法
示例
将数字四舍五入到最接近的整数:
System.out.println(Math.round(0.60));
System.out.println(Math.round(0.40));
System.out.println(Math.round(5));
System.out.println(Math.round(5.1));
System.out.println(Math.round(-5.1));
System.out.println(Math.round(-5.9));
定义和用法
round() 方法将数字四舍五入到最接近的整数。
语法
以下选项之一:
public static long round(double number)
public static int round(float number)
参数值
| 参数 | 描述 |
|---|---|
| number | 必需。要四舍五入的数字。 |
技术细节
| 返回值: | 返回一个 long 值(如果参数是 double 类型)或 int 值(如果参数是 float 类型),该值表示最接近某个数字的整数。 |
|---|---|
| Java 版本: | 任意 |
❮ Math 数学方法

