Learn and Learn

Learn And Learn - great place for tutorials, references and how-to

Java – Find Largest Double Value – floor() Method with Examples

java.lang.Math.floor() method is used to find the largest double value in Java, (closest to positive infinity), that is less than or equal to the argument and is equal to a mathematical integer of a double value for the given input (x – parameter).

 

floor() method exists in Math class of java.lang package.
Since: JDK1.0

 

Declaration of floor() Method

The declaration of floor() method is:

 

Syntax of floor() Method

The syntax of floor() method in Java is:

Example for Syntax of floor() Method

Output:
875.0

Another example for syntax of floor() Method

By importing java.lang package the syntax of floor() method can be used as:

Output:
875.0

 

Special Cases of floor() Method in Java

If the argument value is already equal to a mathematical integer, then the result is the same as the argument.
If the argument is NaN or an infinity or positive zero or negative zero, then the result is the same as the argument.
Example:

Output:

70.0
0.0
0.0
Infinity
-Infinity
NaN

 

Parameters of floor() Method in Java

x – Where x is any valid double input value. This parameter is required.

 

Error Handling

If the x parameter is not a number floor() method returns an error.
If there is no argument (x – input value) passes to the method, the compiler will produce an error.Example

Output:
Error

 

Return Value of floor() Method in Java

floor() 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 of a double value for the given input (x – parameter).the largest (closest to positive infinity) floating-point value that less than or equal to the argument and is equal to a mathematical integer.

 

Java floor() Method Example 1


Output:

largest (closest to positive infinity) double value that is less than or equal to the argument and is equal to a mathematical integer of a Negative Value: -19.0
largest (closest to positive infinity) double value that is less than or equal to the argument and is equal to a mathematical integer of a Positive Value: 27.0
largest (closest to positive infinity) double value that is less than or equal to the argument and is equal to a mathematical integer of Zero: 0.0

 

Java floor() Method Example 2


Output:

1.7976931348623157E308
0.0
NaN
-1022.0
0.0
15.0
0.0
-3.0
-7.88569E8

 

 

LearnAndLearn.com © 2018 - All rights reserved