×

Java Math floor() Method

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

Syntax:

public static double floor(double a)

Parameters:

The parameter ‘a’ represents the value.

Return Value:

The floor () method returns the largest floating-point value that is equal to a mathematical integer and is less than or equal to the argument.

Special cases of the floor() method are as follows:

  • It returns the result same as the argument, if the argument passed is equal to an integer or is a NaN or an infinity or positive zero or negative zero value

Example 1:

public class JavaMathFloorExample1 {
    public static void main(String[] args) {
        double a=10.780;
        //returns the largest double value that is less than or equal to the a
        System.out.println("Largest double value of "+ a+" = "+Math.floor(a));
    }
}

Output:

Largest double value 0.0 = 0.0

Example 2:

public class JavaMathFloorExample2 {
    public static void main(String[] args) {
        double a=10.780/0.0d;
        //It returns the result same as 'a', if 'a' is equal to positive infinity
        System.out.println("Largest double value of "+ a+" = "+Math.floor(a));
    }
}

Output:

Largest double value of Infinity = Infinity

Example 3:

public class JavaMathFloorExample3 {
    public static void main(String[] args) {
        double x=-110.780/0.0d;
        //It returns the result same as x, if x is equal to a Negative infinity
        System.out.println("Largest double value of "+ x+" = "+Math.floor(x));
    }
}

Output:

Largest double value of -Infinity = -Infinity

Example 4:

public class JavaMathFloorExample4 {
    public static void main(String[] args) {
        double a=0.0/0.0d;
        //It returns the result same as a, if a is equal to NaN
        System.out.println("Largest double value of "+ a+" = "+Math.floor(a));
    }
}

Output:

Largest double value of NaN = NaN

Example 5:

public class JavaMathFloorExample5 {
    public static void main(String[] args) {
        double a=0.0d;
        //It returns the result same as a, if a is equal to zero
        System.out.println("Largest double value of "+ a+" = "+Math.floor(a));
    }
}

Output:

Largest double value of 0.0 = 0.0

Related Topics

System Class in Java

The System class provides features including a way to load files and libraries, standard input, standard output, and errors throughput streams, accessibility to outside defined characteristics and environment variables, and...

3 minutes read.

Singleton Design Pattern in Java

In the singleton pattern, a class that only has one instance and offers a universal point of access is taken into consideration. It can also be defined in another way, a...

4 minutes read.

How to create a linked list in Java

Introduction: The linked listing is one type of linear statistics shaped like an array. Not like arrays, linked listing factors aren't stored in a contiguous place. The elements have linked...

3 minutes read.

What is string in Java why it's immutable

String in Java Strings are a series of characters commonly used in Java language, which are considered objects in the Java. To create and manipulate strings, java will provide the String...

4 minutes read.

Java Public Keyword

A Java access modifier is a public keyword. It can be applied to classes, constructors, methods, and variables. It is the type of access modifier that is least constrained. A...

4 minutes read.

Java Boolean hashCode() Method

The hashCode() method of Boolean class returns the hash code for the specified Boolean object or the given Boolean value. Syntax public int hashCode()public int hashCode(boolean value) Parameters The parameter ‘value’ represents the value...

2 minutes read.

Access specifiers in Java

What are access specifiers in Java? Access specifiers in Java are used to determine whether other classes can use a particular field or invoke a particular method. Access specifiers mainly specify...

7 minutes read.

java.lang.NumberFormatException for Input String

java.lang.NumberFormatException for Input String The exception java.lang.NumberFormatException for input string occurs when we try to convert a string into a number format. For example, if someone converts the string “Tutorial & Example”...

3 minutes read.

Bin Packing Problem Java

Assigning some items with known weights to bins with consistent capacities is necessary for the bin packing problem. The goal is to use the smallest possible boxes while ensuring everything is put...

6 minutes read.

ArrayDeque in Java

ArrayDeque The ArrayDeque is one of the essential concepts in java to implement the deque interface. It will allow us to apply a resizable array to implement the Deque interface. This...

8 minutes read.

Java Open File

Java Desktop class give an open() strategy to open a filr. It has a place with a java.awt package. Work area execution is stage subordinate, so it is important to...

5 minutes read.

Java Null Keyword

Null is a term that is only used for literal values in Java. Although it appears to be a term, it is a literal opposite of true and false. Java's...

3 minutes read.

Magnanimous Number in java

Magnanimous Number When the left and right halves of a majestic number are combined, the result is invariably a prime number, which must have at least two digits. The number's left...

3 minutes read.

Bucket Sort in Java

Bucket Sort in JavaBucket sort is also called bin sort. Bucket sort first puts the elements of the array or list into different buckets. The first bucket contains elements of the smallest value. The...

11 minutes read.

Java Math nextDown() Method

The nextDown() method of Math class returns the floating-point number adjacent to the argument in direction of the negative infinity. Syntax: public static double nextDown (double d)public static float nextDown (float f) Parameters: The...

2 minutes read.

Java Boolean toString() Method

The toString() method of Java Boolean class returns a String corresponding to this Boolean object. It returns a string value “true”, if the defined object is true else it returns...

2 minutes read.

Set Matrix Zeros in Java

In coding round interviews, it is frequently asked as the most significant challenge. an m*n matrix is provided. Set the entire column and row of the matrix to 0 if any...

6 minutes read.

Java Variable

The variable is the basic unit of storage in a program. We define a variable using an identifier, a type, and an optional initializer in Java. In Java, variables must be...

4 minutes read.

StringBuilder in Java

StringBuilder in Java Java StringBuilder class is introduced since JDK 1.5. The StringBuilder class is mainly used to create modifiable or mutable strings. Note that the StringBuilder class is not synchronized....

7 minutes read.

Java Class Syntax

A class is a fundamental building piece in object-oriented programming. It can be characterised as a template that outlines the information and actions connected to the creation of a class....

3 minutes read.