Java .ceil()
Anonymous contributor
Published Dec 12, 2022
Contribute to Docs
The Math.ceil() method returns the double value that is a mathematical integer and is greater than or equal to the original value.
Syntax
Math.ceil(num)
- The result is the same as the argument if the argument value is already equal to a mathematical integer.
- The result is identical to the argument if the argument is
NaN, +/- infinity, or +/- zero. - The parameter
numis of typedouble. - The result is of type
double
Example 1
The following example demonstrates using .ceil():
// Example.javapublic class Example {public static void main(String args[]) {Double value1 = 8.3;Double value2 = 8.9;System.out.println(Math.ceil(value1));System.out.println(Math.ceil(value2));}}
This results in the following output:
9.09.0
Example 2
The following example demonstrates using .ceil() with negative numbers:
// Example.javapublic class Example {public static void main(String args[]) {Double value1 = -0.5;Double value2 = -1.3;System.out.println(Math.ceil(value1));System.out.println(Math.ceil(value2));}}
This results in the following output:
-0.0-1.0
All contributors
- Anonymous contributor
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.
Learn Java on Codecademy
- Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
- Includes 6 Courses
- With Professional Certification
- Beginner Friendly.75 hours
- Learn to code in Java — a robust programming language used to create software, web and mobile apps, and more.
- Beginner Friendly.17 hours