浮点值的输出有什么不同?

use*_*222 2 c

#include <stdio.h>

int main() {
    float a = 0.7;
    int c;
    c = a < 0.7;
    printf("%d", c);
}
Run Code Online (Sandbox Code Playgroud)

打印输出为1虽然除了0.7,7.7和0.9之外所有情况都打印0,为什么会这样?它也应该是0,因为'<'运算符的优先级大于'='运算符

n. *_* m. 13

0.7不能完全表示为一个float值,因此a存储它的一些近似值.这里的问题是文字0.7具有类型double,因此使用更精确的近似值0.7来表示它.这种近似可能与任一方向上不太精确的近似不同.

要修复,请使用double变量或float文字0.7f.