- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Get ceiling value of a number using Math.ceil in Java
In order to get the ceiling value of a number in Java, we use the java.lang.Math.ceil() method. The Math.ceil() method returns the smallest (closest to negative infinity) double value which is greater than or equal to the parameter and has a value which is equal to a mathematical integer on the number line. If the parameter is NaN or an infinity or positive zero or negative zero, then the result is the same as the argument. If the argument value is less than zero but greater than -1.0, then the value returned is negative zero.
Declaration − The java.lang.Math.ceil() method is declared as follows −
public static double ceil(double a)
Let us see a program to get the ceiling value of a number in Java.
Example
import java.lang.Math; public class Example { public static void main(String[] args) { // declaring and initialising some double values double a = -100.01d; double b = 34.6; double c = 600; // printing their ceiling values System.out.println("Ceiling value of " + a + " = " + Math.ceil(a)); System.out.println("Ceiling value of " + b + " = " + Math.ceil(b)); System.out.println("Ceiling value of " + c + " = " + Math.ceil(c)); } }
Output
Ceiling value of -100.01 = -100.0 Ceiling value of 34.6 = 35.0 Ceiling value of 600.0 = 600.0
Advertisements