Home » Core Java » math » Find floor 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 floor value of a number

With this example we are going to demonstrate how to find the floor value of a number, using the floor(double a) API method of Math. Math API provides methods for performing basic numeric operations such as the elementary exponential, logarithm, square root, and trigonometric functions. In short, to find the floor value of a number you should:

  • Use floor(double a) method of Math. The method returns the largest (closest to positive infinity) double value that is less than or equal to the argument and is equal to a mathematical integer.

Let’s take a look at the code snippet that follows:  

package com.javacodegeeks.snippets.core;

public class FloorValue {

	public static void main(String args[]) {

		// All the examples return the largest (closest to positive infinity) 
		//double value that is not greater than the argument and is equal to a
		//mathematical integer.
		
	    System.out.println(Math.floor(70.1));
	   
	    System.out.println(Math.floor(17.5));
	   
	    System.out.println(Math.floor(-30));
	   
	    System.out.println(Math.floor(-92.4));

	    System.out.println(Math.floor(0));

	}
}

Output:

70.0
17.0
-30.0
-93.0
0.0

  
This was an example of how to find the floor 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