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 261 views
1 answer 256 views
1 answer 203 views
1 answer 205 views
1 answer 247 views
1 answer 215 views
1 answer 200 views
...