超简单c语言问题,路过帮忙看一下

来源:百度知道 编辑:UC知道 时间:2024/06/09 21:09:40
#include<string.h>
main()
{
float f = 138.3576278;
double d = 138.3576278;
printf("%f\n",138.3576278);
printf("%lf\n%f", f, d);
getch();
}
的结果为什么是:
138.357628
138.357620
138.357628
printf("%lf\n%f", f, d); 改为printf("%f\n%f", f, d);结果一样

printf("%f\n",138.3576278); //输出浮点
呵呵
你看float f是什么,是单精度的
他的精度不会达到双精度那么高!
所以使用的使用就可以把其后面多出的位省略为0 了

如果你改成double f;那你就可以正常输出了
double f = 138.3576278;
double d = 138.3576278;

float 的精度问题