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

Java Math.ceil() method

Java Math.ceil() method

The java.lang.Math.ceil() method in Java Math is used to find the smallest integer value which is greater than or equal to the logical integer or argument.

Syntax

public static double ceil(double x)

Parameters

x= This parameter is used for a value

Returns

This method is used to returns smallest floating point value that is greater than or equal to the argument and is equal to a mathematical integer.

  1. If the statement is double positive or negative, the ceiling value will be returned by this form.
  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.
  4. This procedure will return Zero with the same sign as the argument if the argument is positive or negative Zero.
  5. This method returns Negative Zero as output if the argument is less than Zero but greater than -1.0.

Java Math.ceil() Method Example 1


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

Output:
14.0

Java Math.ceil() Method Example 2


public class Main  
{  
    public static void main(String[] args)   
    {  
        double x = -14.13;  
        System.out.println(Math.ceil(x));  
    }  
}  

Output:
-14.0