c如何输出高精度浮点型数

发布时间 2023-04-24 20:50:32作者: 败人两字非傲即惰
环境:cygwin64的gcc 
(mingw64的gcc不行)
int main(int argc, char const *argv[])
{
    long double ld=1.23L;
    printf("1%Lf\n",ld);
    double d=1.3456789123;
    printf("2%f\n",d);
    printf("3%lf\n",d);
    printf("4%llf\n",d);
    long double ld2=(long double)1.3456789123L;
    printf("5%f\n",ld2);
    printf("6%lf\n",ld2);
    printf("7%Lf\n",ld2);
    printf("8%llf\n",ld2);
    printf("9%f\n",(1.3456789123L));
    printf("0%lf\n",1.3456789123L);
    printf("1%Lf\n",1.3456789123L);
    printf("1%.15Lf\n",1.3456789123L);
    printf("2%llf\n",1.3456789123L);
    printf("3%.10f\n",1.3456789123L);
    printf("4%lf\n",1.3456789123L);//Lf 
    printf("5%.15Lf\n",1.3456789123L);
    printf("6%llf\n",1.3456789123L);//  llf不行
    long double x = 1.3456789123;
    printf("7%.15Lf\n", x);
    printf("%.15Lf %d %d %d %d\n",ld,sizeof(ld),sizeof(1e-7L),sizeof((long double)1e-7),sizeof(1e-7));
    return 0;
}
View Code

输出:

04.c: 在函数‘main’中:

04.c:4:5: 警告:隐式声明函数‘printf’ [-Wimplicit-function-declaration]
4 | printf("1%Lf\n",ld);
| ^~~~~~
04.c:4:5: 警告:隐式声明与内建函数‘printf’不兼容
04.c:1:1: 附注:include ‘<stdio.h>’ or provide a declaration of ‘printf’
+++ |+#include <stdio.h>
1 | int main(int argc, char const *argv[])
11.230000
21.345679
31.345679
41.345679
50.000000
60.000000
71.345679
80.000000
90.000000
00.000000
11.345679
11.345678912300000
20.000000
30.0000000000
40.000000
51.345678912300000
60.000000
71.345678912300000
1.230000000000000 16 16 16 8