How to Find Floor Value of a Number in Java


In this example, let us see how to find a floor value of a number with floor method of java Math class. Here the floor method will return the largest interger which is not grater than the value.

Source Code

package com.beginner.examples;

public class FloorExample {

    public static void main(String[] args){
    	//return the largest integer which is not more than the argument value.
    	System.out.println(Math.floor(6));
        System.out.println(Math.floor(6.3));
        System.out.println(Math.floor(-12.6));
        //returns 0
        System.out.println(Math.floor(0));
    }
}

Output:

6.0
6.0
-13.0
0.0
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments