Java.lang.StrictMath 类

java.lang.StrictMath.floor() 方法通过向下舍入指定数字返回下一个最低整数值,如果必要的。换句话说,它将给定数字的小数向下舍入。在特殊情况下,它返回以下内容:

  • 如果参数值已经是整数,则结果与参数相同。
  • 如果参数为 NaN 或无穷大或正零或负零,则结果与参数相同。

语法

public static double floor(double a) 

参数

a 指定一个数字。

返回值

返回如有必要,通过向下舍入指定数字来获取下一个最低整数值。

例外

不适用。

示例:

在下面的例子中,floor()方法用于将指定数字的小数向下舍入。

import java.lang.*;

public class MyClass {
 public static void main(String[] args) {
  System.out.println(StrictMath.floor(10.5)); 
  System.out.println(StrictMath.floor(-10.5));
  System.out.println(StrictMath.floor(0.5)); 
  System.out.println(StrictMath.floor(-0.5));       
 }
}

上述代码的输出将是:

10.0
-11.0
0.0
-1.0