Xcode编译C语言显示完整浮点数

我用Xcode作为编译器学习C语言,代码如下:

#include <stdio.h>
int main(void)
{
    float weight;
    float value;
    printf("are you worth your weight in rhodium?\n");
    printf("let's check it out.\n");
    printf("please enter your weight in pounds: ");
    scanf("%f", &weight);
    value = 770 * weight * 14.5833;
    printf("your weight in rhodium is worth $%.2f.\n", value);
    printf("you are easily worth that! If rhodium prices drop,\n");
    printf("eat more to maintain your value.\n");
    return 0;
}

按理说代码应该没有问题,但是我编译后输出结果却是这样:

are you worth your weight in rhodium?
let's check it out.
please enter your weight in pounds: 150
your weight in rhodium is worth $310815099620643345268736.00.
you are easily worth that! If rhodium prices drop,
eat more to maintain your value.

另外,我发现Xcode中有以下内容:
1
我用其他编译器显示的是正确的结果。请问为什么Xcode中会变成这样奇怪的数字,应该如何设置或修改?
菜鸟拜谢大神~~~!!!

阅读 4.9k
1 个回答

这是Xcode 的debug显示,跟程序的输出没关系,取决于Xcode debug 对于各种类型变量的显示方式

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进