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 方法