首页 > 解决方案 > 为什么在打印 double 和 long double 数据类型时我只看到 6 个小数位

问题描述

我的问题是我的 IDE(我不知道;也许它可能是编译器等)不能正确识别 double 和 long double 数据类型。

这是我的基本示例:

#include <stdio.h>
#include <stdlib.h>

int main()
{
    double x=1.126462842684262264;
    long double y=1.126462842684262264;
    printf("x = %lf \n",x);
    printf("x = %f \n",x);

    printf("y = %lf \n",y);
    printf("y = %Lf \n",y);

    return 0;
}

输出是

x = 1.126463
x = 1.126463
y = 1.126463
y = 1.126463

Process returned 0 (0x0)   execution time : 0.019 s
Press any key to continue.

通常,长双精度是小数点后 19 位,双精度是小数点后 15 位。为什么会发生这种情况以及如何解决?

标签: c

解决方案


推荐阅读