Java Math ceil()

The ceil() method rounds the specified double value upward and returns it. The rounded value will be equal to the mathematical integer. That is, the value 3.24 will be rounded to 4.0 which is equal to integer 4.

Example

class Main {
  public static void main(String[] args) {

double a = 3.24; System.out.println(Math.ceil(a));
} } // Output: 4.0

Syntax of Math.ceil()

The syntax of the ceil() method is:

Math.ceil(double value)

Here, ceil() is a static method. Hence, we are accessing the method using the class name, Math.


ceil() Parameters

The ceil() method takes a single parameter.

  • value - number which is to be rounded upward

ceil() Return Value

  • returns the rounded value that is equal to the mathematical integer

Note: The returned value will be the smallest value that is greater than or equal to the specified argument.


Example: Java Math.ceil()

class Main {
  public static void main(String[] args) {

    // Math.ceil() method
    // value greater than 5 after decimal
    double a = 1.878;
System.out.println(Math.ceil(a)); // 2.0
// value equals to 5 after decimal double b = 1.5;
System.out.println(Math.ceil(b)); // 2.0
// value less than 5 after decimal double c = 1.34;
System.out.println(Math.ceil(c)); // 2.0
} }

Recommended Tutorials

Did you find this article helpful?