0.7 is not less than 0.7 but wrong result gets printed [duplicate]
问题 This question already has answers here : strange output in comparison of float with float literal (8 answers) Floating point comparison `a != 0.7` [duplicate] (3 answers) Closed 5 years ago . Here 'a' should get printed as 0.7 < 0.7 is false, but 'c' is printed. #include<stdio.h> void main() { float a=0.7; if(a<0.7) printf("c"); else printf("a"); } 回答1: You seem to misunderstand floating point numbers. See this question. One thing you can do is think "Well, it will never be exactly 0.7, so