- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Java floor() method with Examples
The java.lang.Math.floor() 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. Special cases −
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.
Let us now see an example to implement the floor() method in Java −
Example
import java.lang.*; public class Demo { public static void main(String[] args) { // get two double numbers double x = 60984.1; double y = -497.99; // call floor and print the result System.out.println("Math.floor(" + x + ")=" + Math.floor(x)); System.out.println("Math.floor(" + y + ")=" + Math.floor(y)); System.out.println("Math.floor(0)=" + Math.floor(0)); } }
Output
Math.floor(60984.1)=60984.0 Math.floor(-497.99)=-498.0 Math.floor(0)=0.0
Example
Let us now see another example wherein we will be checking for negative and other values −
import java.lang.*; public class Demo { public static void main(String[] args) { // get two double numbers double x = 0.0; double y = -5.7; double z = 1.0/0; // call floor and print the result System.out.println("Math.floor(" + x + ")=" + Math.floor(x)); System.out.println("Math.floor(" + y + ")=" + Math.floor(y)); System.out.println("Math.floor(" + z + ")=" + Math.floor(z)); } }
Output
Math.floor(0.0)=0.0 Math.floor(-5.7)=-6.0 Math.floor(Infinity)=Infinity
- Related Articles
- Java toDegrees() method with Examples
- Java signum() method with Examples
- Java lang.Long.toBinaryString() method with Examples
- Java cbrt() method with Examples
- Java ceil() method with Examples
- Java sqrt() method with Examples
- Java streams counting() method with examples
- Java Signature getAlgorithm() method with Examples
- Java Signature getInstance() method with Examples
- Java Signature getProvider() method with Examples
- Java Signature initSign() method with Examples
- Java Signature toString() method with Examples
- Java lang Integer.toHexString() Method with Examples
- Java lang Long.toOctalString() Method with Examples
- NavigableSet Class floor() method in Java

Advertisements