📜  Java中的 StrictMath floor() 方法

📅  最后修改于: 2022-05-13 01:55:31.491000             🧑  作者: Mango

Java中的 StrictMath floor() 方法

Java.lang.StrictMath.floor()是内置方法,它返回最大的双精度值,小于或等于给定的参数并且等于整数值。

  • 当给定参数等于整数时,结果与参数相同。
  • 结果与给定参数为 NaN、无穷大、正零或负零时的参数相同。

句法 :

public static double floor(double num)

参数:此方法接受一个参数num ,它是 double 类型。
返回值:该方法返回最接近正无穷大、小于或等于参数且等于整数的最大值。
例子 :

Input: num = 9.6
Output: 9.0

Input: num = -7.8
Output: -8.0

下面的程序说明了Java.lang.StrictMath.floor() 方法:
方案一:

java
// Java program to illustrate the
//java.lang.StrictMath.floor()
 
import java.lang.*;
 
public class Geeks {
 
public static void main(String[] args) {
 
    double num1 = 7.8, num2 = 1.4 ;
 
    double fValue = StrictMath.floor(num1);
    System.out.println("The floor value of "+
                             num1+" = " + fValue);
 
    fValue = StrictMath.floor(num2);
    System.out.println("The floor value of "+
                             num2+" = " + fValue);
}
}


java
// Java program to illustrate the
//java.lang.StrictMath.floor()
 
import java.lang.*;
 
public class Geeks {
 
public static void main(String[] args) {
 
    double num1 = -7.8, num2 = -1.4 ,num3 = 0.1 ;
 
    double fValue = StrictMath.floor(num1);
    System.out.println("The floor value of "+
                             num1+" = " + fValue);
 
    fValue = StrictMath.floor(num2);
    System.out.println("The floor value of "+
                             num2+" = " + fValue);
 
    fValue = StrictMath.floor(num3);
    System.out.println("The floor value of "+
                             num3+" = " + fValue);
 
}
}


输出:
The floor value of 7.8 = 7.0
The floor value of 1.4 = 1.0

程序2:

Java

// Java program to illustrate the
//java.lang.StrictMath.floor()
 
import java.lang.*;
 
public class Geeks {
 
public static void main(String[] args) {
 
    double num1 = -7.8, num2 = -1.4 ,num3 = 0.1 ;
 
    double fValue = StrictMath.floor(num1);
    System.out.println("The floor value of "+
                             num1+" = " + fValue);
 
    fValue = StrictMath.floor(num2);
    System.out.println("The floor value of "+
                             num2+" = " + fValue);
 
    fValue = StrictMath.floor(num3);
    System.out.println("The floor value of "+
                             num3+" = " + fValue);
 
}
}
输出:
The floor value of -7.8 = -8.0
The floor value of -1.4 = -2.0
The floor value of 0.1 = 0.0