# Java StrictMath floor() method with example

StrictMath Class floor() method: Here, we are going to learn about the floor() method of StrictMath Class with its syntax and example.
Submitted by Preeti Jain, on December 25, 2019

## StrictMath Class floor() method

• floor() method is available in java.lang package.
• In this method, if the value of the given positive argument after decimal point is 0 or greater than 0 so in that case, it returns the same number before decimal point else if the value of the given negative argument after decimal point is greater than 0 so it returns (the same number +1) before decimal point.
• floor() method is a static method so it is accessible with the class name and if we try to access the method with the class object then we will not get any error.
• floor() method does not throw any exception.

Syntax:

```    public static double floor(double d);
```

Parameter(s):

• double d – represents the double type value whose floor value to be found.

Return value:

The return type of this method is double – it returns the greatest floating-point value of the given argument and the argument value may be less than or equal to the given argument.

Note:

• If we pass NaN as an argument, method returns the same value (NaN).
• If we pass an infinity (positive or negative), method returns the same value (i.e. positive or negative infinity).
• If we pass zero (0) positive or negative, method returns the same.

Example:

```// Java program to demonstrate the example of
// floor(double d) method of StrictMath Class.

public class Floor {
public static void main(String[] args) {
// variable declarations
double d1 = 7.0 / 0.0;
double d2 = -7.0 / 0.0;
double d3 = 0.0;
double d4 = -0.0;
double d5 = -123.1;
double d6 = 123.456;

// Display previous value of d1,d2,d3,d4,d5 and d6
System.out.println("d1: " + d1);
System.out.println("d2: " + d2);
System.out.println("d3: " + d3);
System.out.println("d4: " + d4);
System.out.println("d5: " + d5);
System.out.println("d6: " + d6);

// Here , we will get (Infinity) because we are
// passing parameter whose value is (infinity)
System.out.println("StrictMath.floor(d1): " + StrictMath.floor(d1));

// Here , we will get (-Infinity) because we are passing
// parameter whose value is (-infinity)
System.out.println("StrictMath.floor(d2): " + StrictMath.floor(d2));

// Here , we will get (0.0) because we are
// passing parameter whose value is (0.0)
System.out.println("StrictMath.floor(d3): " + StrictMath.floor(d3));

// Here , we will get (-0.0) because we are passing
// parameter whose value is (-0.0)
System.out.println("StrictMath.floor(d4): " + StrictMath.floor(d4));

// Here , we will get (-124.0) because we are
// passing parameter whose value is (-123.1)
System.out.println("StrictMath.floor(d5): " + StrictMath.floor(d5));

// Here , we will get (123.0) because we are
// passing parameter whose value is (123.456)
System.out.println("StrictMath.floor(d6): " + StrictMath.floor(d6));
}
}
```

Output

```d1: Infinity
d2: -Infinity
d3: 0.0
d4: -0.0
d5: -123.1
d6: 123.456
StrictMath.floor(d1): Infinity
StrictMath.floor(d2): -Infinity
StrictMath.floor(d3): 0.0
StrictMath.floor(d4): -0.0
StrictMath.floor(d5): -124.0
StrictMath.floor(d6): 123.0
```

TOP Interview Coding Problems/Challenges

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates