Home » Core Java » math » Find ceiling value of a number

About Ilias Tsagklis

Ilias is a software developer turned online entrepreneur. He is co-founder and Executive Editor at Java Code Geeks.

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.

Do you want to know how to develop your skillset to become a Java Rockstar?

Subscribe to our newsletter to start Rocking right now!

To get you started we give you our best selling eBooks for FREE!

 

1. JPA Mini Book

2. JVM Troubleshooting Guide

3. JUnit Tutorial for Unit Testing

4. Java Annotations Tutorial

5. Java Interview Questions

6. Spring Interview Questions

7. Android UI Design

 

and many more ....

 

Receive Java & Developer job alerts in your Area

 

Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 Comments
Inline Feedbacks
View all comments