使用 Java 中的 Math.floor 獲取一個數的地板值
要想獲得一個數的地板值,我們使用 java.lang.Math.floor() 方法。Math.floor() 方法會返回一個最大的(最接近於正無窮)的雙精度值,該值小於或等於引數並且等於數軸上的一個數學整數。如果引數是 NaN 或無窮大或正零或負零,那麼結果與引數相同。
宣告 - java.lang.Math.floor() 方法宣告如下 −
public static double floor(double a)
讓我們看看一個 java 程式,瞭解如何獲得一個數的地板值。
示例
import java.lang.Math; public class Example { public static void main(String[] args) { // declaring and initialising some double values double a = -100.01d; double b = 34.6; double c = 600; // printing their floor values System.out.println("Floor value of " + a + " = " + Math.floor(a)); System.out.println("Floor value of " + b + " = " + Math.floor(b)); System.out.println("Floor value of " + c + " = " + Math.floor(c)); } }
輸出
Floor value of -100.01 = -101.0 Floor value of 34.6 = 34.0 Floor value of 600.0 = 600.0
廣告