c - 为什么在打印 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 位。为什么会发生这种情况以及如何解决?
- 我正在使用 GNU GCC 编译器。
- 我的 IDE 是 CodeBlocks。
解决方案
推荐阅读
- python - 为什么这个答案通过了 Leetcode Q41
- javascript - 箭头函数中的 JavaScript 扩展运算符
- python - 如何匹配 Python 中的 URL(在 Atom 中可以,但在 Pycharm 中运行错误)?
- python - 系统上的软件包更新会影响虚拟环境?
- python - 在 Web 应用程序中保存多个 Keras 模型
- r - ggplot2:使用“limits =”缩放x轴时制作一个仅显示可见数据系列的图例
- node.js - JS - Laravel Mix/NPM.js:变量 twemoji.parse 未找到/未定义
- go - 为什么gorm 没有在日志中报告插入错误?
- php - 如何在 Symfony 2 中全局更改 Monolog 的默认日期时区?
- c++ - 如何在 Visual Studio 中跳过 Debug Assertion Failed 并直接中断