C++舍入错误

Sha*_*ura -1 c++ math rounding

可能重复:
C中整数除法的行为是什么?

为什么这行代码没有返回任何内容?

float i = 10/3;
if (i>3) cout << i;
Run Code Online (Sandbox Code Playgroud)

如果有帮助,请使用CodeBlocks编译器.

asc*_*ler 6

因为10/3 == 3.整数除法向零截断.要强制它为浮点除法而不是整数除法,请尝试使用10.0/3或等float(10)/3.