Java StrictMath floor()方法
java.lang.StrictMath.floor() 是一个内置的方法,它返回最大的双倍值,小于或等于给定的参数,并且等于整数值。
当给定参数等于整数时,其结果与参数相同。当给定参数为NaN、无穷大、正0或负0时,结果与参数相同。语法:
public static double floor(double num)
参数: 该方法接受一个参数 num ,该参数为双数类型。
返回值: 该方法返回最大的值,该值最接近正无穷大,小于或等于参数,并且等于一个整数。
示例
Input: num = 9.6Output: 9.0Input: num = -7.8Output: -8.0
下面的程序说明了java.lang.StrictMath.floor()方法:
程序1
// 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);}}输出
The floor value of 7.8 = 7.0The floor value of 1.4 = 1.0
程序2
// 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.0The floor value of -1.4 = -2.0The floor value of 0.1 = 0.0
