更正 C 中双数的 printf 格式
Correct printf formats for double numbers in C
什么意思:
#include <stdio.h>
int main(){
double bmax = 31.4159265;
printf("%1.4e\n", bmax);
}
%1.4e
是什么意思?我知道 %f
是双倍的。
%e specifier is used to print value of float\double in exponential format.
所以这里%1.4e
会打印小数点前1位和小数点后4位
所以如果 bmax=12.242
那么输出将是 1.2242e+01
.
什么意思:
#include <stdio.h>
int main(){
double bmax = 31.4159265;
printf("%1.4e\n", bmax);
}
%1.4e
是什么意思?我知道 %f
是双倍的。
%e specifier is used to print value of float\double in exponential format.
所以这里%1.4e
会打印小数点前1位和小数点后4位
所以如果 bmax=12.242
那么输出将是 1.2242e+01
.