可能重复:
浮点比较
#include<stdio.h>
#include<conio.h>
int main()
{
float i=0.7;
clrscr();
if(i < 0.7)
printf("If Block");
else
printf("Else Block");
getch();
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我不明白whay输出将是"If block".....请帮助为什么if部分被执行?
Omk*_*ant 13
实际上i是0.69999999998它的浮动表示.
i=0.7在内存中分配时,无法double precision按照您的想法表示0.7 .
所以之间的比较float,并double导致输入推广和在这种情况下,i低于0.7这是双.
| 归档时间: |
|
| 查看次数: |
1817 次 |
| 最近记录: |