What is Math.floor() in JAVA?

The floor() function returns the largest double value that is less than or equal to a specific number.

Figure 1, below, shows the mathematical representation of the floor() function.

Figure 1: Mathematical representation of floor() function

Syntax

double floor(number num)

Parameter

This function requires a number as a parameter.

The number can be int, float, double, or long.

Return Value

floor() returns the largest double value that is less than or equal to a specific number.

Code

class JAVA {
public static void main( String args[] ) {
//integer
System.out.println("Math.floor(2):");
System.out.println(Math.floor(2));
//positive double value
System.out.println("Math.floor(2.56):");
System.out.println(Math.floor(2.56));
//negative double value
System.out.println("Math.floor(-2.36):");
System.out.println(Math.floor(-2.36));
}
}

Free Resources