【发布时间】:2014-10-07 14:39:18
【问题描述】:
我有以下代码:
public static final long KILOMETER_IN_METERS = 1000;
public static int getKilometers(int distanceInMeter) {
return (int) Math.floor(distanceInMeter / KILOMETER_IN_METERS);
}
对于带有 return 语句的行,Sonar 说:
积分除法结果转换为双精度或浮点数Here is the full description of this bug.
据我了解,它说存在 int/int 除法,其结果可能是 浮点值,但我可能错了。
我该如何正确处理这种情况?
【问题讨论】:
标签: java casting integer-division