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)
参数值
参数 | 描述 |
---|---|
数字 | 必需。要四舍五入的数字。 |
技术详情
返回 | 一个 long 值(如果参数是 double 类型)或 int 值(如果参数是 float 类型),表示最接近该数字的整数。 |
---|---|
Java 版本 | 任何 |
❮ Math 方法