How to round down the result of integer division in Java

1 Answer

0 votes
public class MyClass {
    public static void main(String args[]) {
        int a = 248, b = 9;
        
        double result = (double)a / b;
        int result_round_down = (int)Math.floor((double)a / b);
 
        System.out.println(result);
        System.out.println(result_round_down);
    }
}




/*
run:
 
27.555555555555557
27
 
*/

 



answered Aug 18, 2021 by avibootz

Related questions

1 answer 171 views
1 answer 159 views
1 answer 121 views
1 answer 108 views
1 answer 156 views
1 answer 132 views
1 answer 106 views
...