3 回答
TA贡献1848条经验 获得超10个赞
#include <float.h>int Digs = DECIMAL_DIG;double OneSeventh = 1.0/7.0;printf("%.*e\n", Digs, OneSeventh);// 1.428571428571428492127e-01
OneSeventh = 1.0/7.0
double
OneSeventh before = 0.1428571428571428 214571170656199683435261249542236328125OneSeventh = 0.1428571428571428 49212692681248881854116916656494140625OneSeventh after = 0.1428571428571428 769682682968777953647077083587646484375
double
<float.h>
FLT_DECIMAL_DIG 6, 9 (float) (C11)DBL_DECIMAL_DIG 10, 17 (double) (C11)LDBL_DECIMAL_DIG 10, 21 (long double) (C11)DECIMAL_DIG 10, 21 (widest supported floating type) (C99)
FLT_DIG 6, 6 (float)DBL_DIG 10, 15 (double)LDBL_DIG 10, 18 (long double)
#ifdef DBL_DECIMAL_DIG #define OP_DBL_Digs (DBL_DECIMAL_DIG)#else #ifdef DECIMAL_DIG #define OP_DBL_Digs (DECIMAL_DIG) #else #define OP_DBL_Digs (DBL_DIG + 3) #endif#endif
<float.h>
.
"%e"
- 1
-1 is not in the initial
printf("%.*e\n", OP_DBL_Digs - 1, OneSeventh);// 1.4285714285714285e-01
"%f"
OneSeventh/1000000.0
OP_DBL_Digs + 6
printf("%.*f\n", OP_DBL_Digs , OneSeventh);// 0.14285714285714285printf("%.*f\n", OP_DBL_Digs + 6, OneSeventh/1000000.0); // 0.00000014285714285714285
"%f"
TA贡献1829条经验 获得超9个赞
如果您的类型是浮动的:使用 printf("%.9g", number)
.如果您的类型是双重的:使用 printf("%.17g", number)
.
%f
float.h
FLT_DECIMAL_DIG
DBL_DECIMAL_DIG
.
TA贡献1871条经验 获得超8个赞
%a
如果存在基2中的精确表示,并且在其他情况下足够大,足以区分类型Double的值,则默认精度就足以表示值的精确表示。
添加回答
举报