The ceiling function returns the smallest whole number that is greater than or equal to the input. This function is similar to the floor function and is written as Math.ceil(input)
. It only takes and returns double
data types. Take a look at the example below.
CeilingMethodExample.java
package exlcode;
public class CeilingMethodExample {
// Returns smallest integer that is greater than or equal to the argument
public static double exampleVariableOne = Math.ceil(10.4);
public static double exampleVariableTwo = Math.ceil(-20.4);
public static void main(String[] args) {
System.out.println(exampleVariableOne);
System.out.println(exampleVariableTwo);
}
}
The ceiling function returns the smallest whole integer greater than or equal to the input and prints it as a double
with a decimal. This function does not truncate, it rounds up, with the exception of inputs between 0 and -1.0, this returns "-0.0".