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 264 views
1 answer 257 views
1 answer 204 views
1 answer 207 views
1 answer 249 views
1 answer 216 views
1 answer 201 views
...