math

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.

Ilias Tsagklis

Ilias is a software developer turned online entrepreneur. He is co-founder and Executive Editor at Java Code Geeks.
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
Back to top button