相关疑难解决方法(0)

浮点比较中的问题

void main()
{
    float f = 0.98;
    if(f <= 0.98)
        printf("hi");
    else
        printf("hello");
    getch();
}
Run Code Online (Sandbox Code Playgroud)

我在这里遇到这个问题.使用不同的浮点值得到不同的结果.为什么会这样?

c floating-point floating-point-conversion

6
推荐指数
2
解决办法
2875
查看次数

浮点比较`a!= 0.7`

可能重复:
浮点比较中的问题

#include <stdio.h>
#include <conio.h>

main()
{
    float a = 0.7;
    if(a < 0.7)
        printf("C");
    else
        printf("C++");
}
Run Code Online (Sandbox Code Playgroud)

在上面的代码中,输出是C.我在Code :: Blocks和Pelles C中尝试了这个代码,但得到了相同的答案.我想详细了解这个的原因!

c floating-point comparison

4
推荐指数
2
解决办法
6439
查看次数