Find ceil and floor values in Java

Ceil value is the equivalent integer value by rounding up a float or double to the nearest integer (eg ceil of 12.1 is 13).

Floor value is the equivalent integer value by rounding down a float or double to the nearest integer (eg floor of 12.8 is 12).

ceil(double a) of Math class can be used to rounding up a double value and floor method can be used to rounding down a double value.

The methods are static, so it can be called directly using class name without creating object.


Example 1 (for ceil)

class MathTest{

public static void main(String args[]){

double dc=12.19;

double dctoc=Math.ceil(dc);

System.out.println("Ceil of value "+dc+" is "+dctoc);

}

}

Output 1

Ceil of value 12.19 is 13.0


Example 2 (for floor)

class MathTest{

public static void main(String args[]){

double df=1.9;

double dftof=Math.floor(df);

System.out.println("Floor of value "+df+" is "+dftof);

}

}

Output 2

Floor of value 1.9 is 1.0