代码检查:可能的小数部分丢失
此检查会报告结果随后仅被转换为 float、 double 或 decimal 的整数除法。 在这种情况下,小数部分在转换发生前就已丢失。
示例
int total = 1;
int count = 2;
float average = total / count;
这里 total / count 会作为整数除法进行求值,所以结果是 0 ,而不是 0.5。
如何修复
此检查没有专用的快速修复方案。 通常的修复方法是在除法运算前至少让一个操作数为非整数。
int total = 1;
int count = 2;
float average = (float)total / count;
2026年 5月 8日