- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- 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
Get floor value of a number using Math.floor in Java
To get the floor value of a number, we use the java.lang.Math.floor() method. The Math.floor() method returns the largest (closest to positive infinity) double value which is less than or equal to the parameter and has a value which is equal to a mathematical integer on the number line. If the parameter is NaN or an infinity or positive zero or negative zero, then the result is the same as the argument.
Declaration - The java.lang.Math.floor() method is declared as follows −
public static double floor(double a)
Let us see a program to get the floor value of a number in Java.
Example
import java.lang.Math; public class Example { public static void main(String[] args) { // declaring and initialising some double values double a = -100.01d; double b = 34.6; double c = 600; // printing their floor values System.out.println("Floor value of " + a + " = " + Math.floor(a)); System.out.println("Floor value of " + b + " = " + Math.floor(b)); System.out.println("Floor value of " + c + " = " + Math.floor(c)); } }
Output
Floor value of -100.01 = -101.0 Floor value of 34.6 = 34.0 Floor value of 600.0 = 600.0
Advertisements