【问题标题】:How to display large double numbers without scientific notation in C?如何在C中显示没有科学计数法的大双数?
【发布时间】:2017-07-08 08:22:00
【问题描述】:

我怎样才能显示双重喜欢

5000683

而不是 C 中的5.000683e6

我尝试过%d%g%f,但无济于事。

【问题讨论】:

标签: c printf double format-specifiers


【解决方案1】:

看起来%f 工作正常:

#include <stdio.h>

int main()
{
  double d = 5000683;
  printf("%f\n", d);
  printf("%.0f\n", d);

  return 0;
}

这段代码的输出将是

5000683.000000
5000683

第二个printf() 语句将精度设置为0(通过在f 前加上.0)以避免小数点后出现任何数字。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-30
    • 1970-01-01
    • 1970-01-01
    • 2019-07-09
    相关资源
    最近更新 更多