how to printf long double in C? [duplicate]

﹥>﹥吖頭↗ 提交于 2020-05-23 13:16:29

问题


[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


回答1:


The right format specifier for long double in printf() is "%Lf"



来源:https://stackoverflow.com/questions/28120572/how-to-printf-long-double-in-c

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!