English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Java Basic Tutorial

Java flow control

Java array

Java object-oriented (I)

Java object-oriented (II)

Java object-oriented (III)

Java Exception Handling

Java List

Java Queue (queue)

Java Map collection

Java Set collection

Java input/output (I/O)

Java Reader/Writer

Java other topics

Java Math ceil() usage and example

Java Math Mathematical Methods

The Java Math ceil() method rounds the specified double value up and returns it.

The rounded value should be equal to a mathematical integer. That is, the value3.4Should be rounded to4.0, equal to an integer4.

The syntax of the ceil() method is:

Math.ceil(double value)

Note:ceil() is a static method. Therefore, we can access this method using the class name Math.

ceil() parameter

  • value - The number to be rounded up

Return value of ceil()

  • Returns the rounded value equal to a mathematical integer

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

Example: Java Math.ceil()

class Main {
  public static void main(String[] args) {
    //Math.ceil() Method.
    //is greater than the decimal point5The value
    double a = 1.878;
    System.out.println(Math.ceil(a));  // 2.0
    //The value after the decimal point is equal to5
    double b = 1.5;
    System.out.println(Math.ceil(b));  // 2.0
    //is less than the decimal point5The value
    double c = 1.34;
    System.out.println(Math.ceil(c));  // 2.0
  }
}

Recommended Tutorials

Java Math Mathematical Methods