What is Math.ceil() in Java?

The ceil() function returns the nearest smallest double value that is greater than or equal to a number.

Figure 1 shows the mathematical representation of the ceil() function.

Figure 1: Mathematical representation of ceil() function

Syntax

double ceil(number num)

Parameter

This function requires a number as a parameter.

The number can be int, float, double, or long.

Return Value

ceil() returns the nearest, smallest double value that is greater than or equal to a number sent as a parameter.

Example

class JAVA {
public static void main( String args[] ) {
//integer
System.out.println("Math.ceil(2):");
System.out.println(Math.ceil(2));
//positive double value
System.out.println("Math.ceil(2.56):");
System.out.println(Math.ceil(2.56));
//negative double value
System.out.println("Math.ceil(-2.36):");
System.out.println(Math.ceil(-2.36));
}
}

Free Resources