當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Java Math.floor()用法及代碼示例

java.lang.Math.floor() 用於查找小於或等於參數且等於 double 值的數學整數的最大整數值。

用法

public static double floor(double a)

參數

x= a value

返回

This method returns largest floating-point value that is less than or equal 
to the argument and is equal to a mathematical integer of a double value.
  • 如果參數為正或負雙精度值,此方法將返回 Floor 值。
  • 如果參數為 NaN,則此方法將返回相同的參數。
  • 如果參數為 Infinity,則此方法將返回與參數相同符號的 Infinity。

例子1

public class FloorExample1
{
    public static void main(String[] args) 
    {
        double x = 94.69;
        // Input positive value, Output floor value of x
        System.out.println(Math.floor(x));
    }
}

輸出:

94.0

例子2

public class FloorExample2
{
    public static void main(String[] args) 
    {
        double x = -39.28;
        // Input negative value, Output floor value of x
        System.out.println(Math.floor(x));
    }
}

輸出:

-40.0

例子3

public class FloorExample3
{
    public static void main(String[] args) 
    {
        double x = 0.0;
        // Input positive zero, Output positive zero 
        System.out.println(Math.floor(x));
    }
}

輸出:

0.0

示例 4

public class FloorExample4
{
    public static void main(String[] args) 
    {
        double x = -7.0 / 0;
        // Input negative infinity, Output negative infinity
        System.out.println(Math.floor(x));
    }
}

輸出:

-Infinity






相關用法


注:本文由純淨天空篩選整理自 Java Math.floor() method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。