How to use floor in Java

2 Answers

0 votes
public class MyClass {
    public static void main(String args[]) {
          
        float f1 = 1.1f, f2 = 1.5f, f3 = 1.6f, f4 = 1.9f, f5 = 0, f6 = 0.001f;
   
        System.out.println(Math.floor(f1));
        System.out.println(Math.floor(f2));
        System.out.println(Math.floor(f3));
        System.out.println(Math.floor(f4));
        System.out.println(Math.floor(f5));
        System.out.println(Math.floor(f6));
    }
}
  
  
  
  
/*
run:
   
1.0
1.0
1.0
1.0
0.0
0.0
   
*/

 



answered Jun 9, 2022 by avibootz
edited Jun 9, 2022 by avibootz
0 votes
public class MyClass {
    public static void main(String args[]) {
         
        float f1 = -1.1f, f2 = -1.5f, f3 = -1.6f, f4 = -1.9f, f5 = -0, f6 = -0.001f;
  
        System.out.println(Math.floor(f1));
        System.out.println(Math.floor(f2));
        System.out.println(Math.floor(f3));
        System.out.println(Math.floor(f4));
        System.out.println(Math.floor(f5));
        System.out.println(Math.floor(f6));
    }
}
 
 
 
 
/*
run:
  
-2.0
-2.0
-2.0
-2.0
0.0
-1.0
  
*/

 



answered Jun 9, 2022 by avibootz
edited Jun 9, 2022 by avibootz
...