Skip to Content

Find floor value of a number using Math.floor

  1. /*
  2.   Find floor value of a number using Math.floor
  3.   This java example shows how to find a floor value of a number using floor method
  4.   of Java Math class. floor method returns the largest interger which is not grater
  5.   than the value.
  6. */
  7.  
  8. public class FindFloorValueExample {
  9.  
  10.   public static void main(String[] args) {
  11.    
  12.     /*
  13.      * To find a floor value, use
  14.      * static double floor(double d) method of Math class.
  15.      *
  16.      * It returns a largest integer which is not grater than the argument value.
  17.      */
  18.    
  19.     //Returns the same value
  20.     System.out.println(Math.floor(70));
  21.    
  22.     //returns largest integer which is not less than 30.1, i.e. 30
  23.     System.out.println(Math.floor(30.1));
  24.    
  25.     //returns largest integer which is not less than 15.5, i.e. 15
  26.     System.out.println(Math.floor(15.5));
  27.    
  28.     //in this case it would be -40
  29.     System.out.println(Math.floor(-40));
  30.    
  31.     //it returns -43.
  32.     System.out.println(Math.floor(-42.4));
  33.    
  34.     //returns 0
  35.     System.out.println(Math.floor(0));
  36.    
  37.   }
  38. }
  39.  
  40. /*
  41. Output would be
  42. 70.0
  43. 30.0
  44. 15.0
  45. -40.0
  46. -43.0
  47. 0.0
  48. */