问题描述
[更新]无论我使用 lf
, Lf
,<$ c,结果仍然相同$ c> llf ...我正在使用代码块来编译和运行我的C程序。我正在使用GNU GCC编译器。我期望。代码如下:
#include< stdio.h>
#include< stdlib.h>
int main()
{
double d = 6.232345235; // 8个字节
长double ld = 5.5767458458;
printf(%lf\n,ld);
返回0;
}
返回值是-0.000000或我不知道的另一个非常大的负数
任何帮助将不胜感激! :D
long double 的正确格式说明符href = http://pubs.opengroup.org/onlinepubs/9699919799/functions/printf.html rel = noreferrer> printf()
是%Lf
[Update] The results would still be the same no matter I use lf
, Lf
, llf
...I am using Code Blocks to compile and run my C program. I am using GNU GCC compiler.
I tried to printf long double float type on different computers including two Windows and one Mac but it turns out that none of them is working as I expected. The code is the following:
#include <stdio.h>
#include <stdlib.h>
int main()
{
double d = 6.232345235; //8 bytes
long double ld = 5.5767458458;
printf("%lf\n", ld);
return 0;
}
Either the return value is -0.000000 or another very huge negative number which I don't remember now.
Any help is greatly appreciated! :D
The right format specifier for long double
in printf()
is "%Lf"
这篇关于如何在C中打印long double?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!