【发布时间】:2011-09-10 03:30:30
【问题描述】:
可能的重复:
Possible Loss of Fraction
What is the behavior of integer division in C?
我是 C 新手,遇到了一些麻烦。以下代码:
int nr = 3;
float fl = nr/10;
printf("%4.1f\n", fl);
按我的预期打印0.0 但不是0.3。有什么问题?
【问题讨论】:
-
@Ólafur:我不认为有关特定 C# 警告消息的问题与有关 C 中整数除法的问题真正重复。
-
这是同一个问题,他正在划分两个整数并失去精度。链接的问题中有很好的解释。
标签: c floating-point