How to cast a double to an int in Java by rounding it down?
casting, java
Solution
Casting to an int implicitly drops any decimal. No need to call Math.floor() (assuming positive numbers)
Simply typecast with (int), e.g.:
System.out.println((int)(99.9999)); // Prints 99
This being said, it does have a different behavior from `Math.floor` which rounds towards negative infinity (@Chris Wong)
Problem
I need to cast a double to an int in Java, but the numerical value must always round down. i.e. 99.99999999 -> 99