Float and Double value creating confusion in c [duplicate]

霸气de小男生 提交于 2019-12-13 03:58:25

问题


I am running this program. But getting strange result.

int  main()
{
float a=.8;
if(a < .8)
    printf("a is small\n");
else
    printf("a is not small\n");

float b=.7;
if(b < .7)
    printf("b is small\n");
else
    printf("b is not small\n");
return 0;
}

It gives me output--

a is not small

b is small


回答1:


Why don't you use 0.7f. 0.7 Is by default double, so we cannot predict it's behaviour



来源:https://stackoverflow.com/questions/17500455/float-and-double-value-creating-confusion-in-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!