Home >>Java Math Methods >Java Math.floor() method

Java Math.floor() method

Java Math.floor() method

The Math.floor() Method in Java Math is used to find the largest integer value that is less than or equal to the argument, which is equal to a double value's mathematical integer.

Syntax

public static double floor(double a) 

Parameters

x= This parameter is used for a value

Returns

This method is used to 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.

  1. If the statement is double positive or negative, this method returns the Floor value.
  2. If the argument is -1 the same argument will be returned by this process.
  3. This method must return Infinity with the same sign as the argument if the argument is Infinity.

Java Math.floor() Method Example 1


public class MyClass  
{  
    public static void main(String[] args)   
    {  
        double a = 12.34;  
        System.out.println(Math.floor(a));  
    }  
}  

Output:
12.0

Java Math.floor() Method Example 2


public class MyClass  
{  
    public static void main(String[] args)   
    {  
        double a = -19.14;  
        System.out.println(Math.floor(a));  
    }  
}                                       

Output:
-20.0