I have the following piece of code:
public static final long KILOMETER_IN_METERS = 1000;
public static int getKilometers(int distanceInMeter) {
return (int) Math.floor(distanceInMeter / KILOMETER_IN_METERS);
}
And for the line with the return statement Sonar says:
Integral division result cast to double or float
Here is the full description of this bug.
As far as I understand, it says there is int/int division whose result could be a floating value, but I could be wrong.
How can I handle this case correctly?