【发布时间】:2017-07-08 08:22:00
【问题描述】:
我怎样才能显示双重喜欢
5000683
而不是 C 中的5.000683e6?
我尝试过%d、%g 和%f,但无济于事。
【问题讨论】:
-
%f: no scientific notation。如果您不想要小数点后的数字,您可以指定precision。
标签: c printf double format-specifiers
我怎样才能显示双重喜欢
5000683
而不是 C 中的5.000683e6?
我尝试过%d、%g 和%f,但无济于事。
【问题讨论】:
%f: no scientific notation。如果您不想要小数点后的数字,您可以指定precision。
标签: c printf double format-specifiers
看起来%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)以避免小数点后出现任何数字。
【讨论】: