Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
这个计算背后一定有一些逻辑。但我无法得到它。正常的数学不会导致这种行为。谁能帮我解释一下原因
printf ("float %f \n", 2/7 * 100.0); 结果打印 1.000000
printf ("float %f \n", 2/7 * 100.0);
为什么这样?我不明白原因
整数除法。2/7 = 0作为整数,0 * 100.0 = 0.0作为浮点数。
2/7 = 0
0 * 100.0 = 0.0
做得到你2.0/7 * 100.0正在寻找的答案。
2.0/7 * 100.0