math
Find ceiling value of a number
In this example we shall show you how to find the ceiling value of a number, using the Math Class. The class Math contains methods for performing basic numeric operations such as the elementary exponential, logarithm, square root, and trigonometric functions. To find the ceiling value of a number one should perform the following steps:
- Use
ceil(double a)
method of Math to get the smallest (closest to negative infinity) double value that is greater than or equal to the argument and is equal to a mathematical integer,
as described in the code snippet below.
package com.javacodegeeks.snippets.core; public class CeilValue { public static void main(String args[]) { // All the examples return the smallest (closest to negative infinity) // double value that is not less than the argument and is equal // to a mathematical integer. System.out.println(Math.ceil(456.1)); System.out.println(Math.ceil(7.5)); System.out.println(Math.ceil(-10)); System.out.println(Math.ceil(-57.4)); System.out.println(Math.ceil(0)); } }
Output:
457.0
8.0
-10.0
-57.0
0.0
This was an example of how to find the ceiling value of a number in Java.