如何在C中显示没有科学计数法的大双数? [英] How to display large double numbers without scientific notation in C?

查看:141
本文介绍了如何在C中显示没有科学计数法的大双数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何显示类似double的

How can I display a double like

5000683

不是C中的 5.000683e6

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

I have tried %d, %g and %f, but to no avail.

推荐答案

看起来%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前缀) )以避免小数点后的任何数字。

The second printf() statement sets the precision to 0 (by prefixing f with .0) to avoid any digits after the decimal point.

这篇关于如何在C中显示没有科学计数法的大双数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆