[英]How to display large double numbers without scientific notation in C?
How can I display a double like 我如何显示双像
5000683
Instead of 5.000683e6
in C? 而不是C中的
5.000683e6
?
I have tried %d
, %g
and %f
, but to no avail. 我尝试了
%d
, %g
和%f
,但无济于事。
It looks like %f
works just fine: 看来
%f
可以正常工作:
#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. 第二个
printf()
语句将精度设置为0(通过给f
加上.0
前缀),以避免小数点后的任何数字。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.