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

前端 未结 1 833
面向向阳花
面向向阳花 2021-01-15 20:59

How can I display a double like

5000683

Instead of 5.000683e6 in C?

I have tried %d, %g and

相关标签:
1条回答
  • 2021-01-15 21:32

    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.

    0 讨论(0)
提交回复
热议问题