How to display large double numbers without scientific notation in C?

被刻印的时光 ゝ 提交于 2019-12-04 02:09:14

问题


How can I display a double like

5000683

Instead of 5.000683e6 in C?

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


回答1:


It looks like %f works just fine:

#include <stdio.h>

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

  return 0;
}

The output of this code will be

5000683.000000
5000683

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



来源:https://stackoverflow.com/questions/42321120/how-to-display-large-double-numbers-without-scientific-notation-in-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!