如何在C中打印long double? [英] how to printf long double in C?

查看:126
本文介绍了如何在C中打印long double?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

[更新]无论我使用 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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆