这是微软的问题
http://cn.voidcc.com/question/p-xqgtlycy-kb.html
https://docs.microsoft.com/en-us ... N&view=msvc-160
The %e and %E format specifiers format a floating point number as a decimal mantissa and exponent. The %g and %G format specifiers also format numbers in this form in some cases. In previous versions, the CRT would always generate strings with three-digit exponents. For example, printf("%e\n", 1.0) would print 1.000000e+000, which was incorrect. C requires that if the exponent is representable using only one or two digits, then only two digits are to be printed.
In Visual Studio 2005 a global conformance switch was added: _set_output_format. A program could call this function with the argument _TWO_DIGIT_EXPONENT, to enable conforming exponent printing. The default behavior has been changed to the standards-conforming exponent printing mode.
下面是有道翻译%e和%e格式说明符将浮点数格式化为十进制尾数和指数。在某些情况下,%g和%g格式说明符也会格式化这种形式的数字。在以前的版本中,CRT总是生成具有三位指数的字符串。例如,printf("%e\n", 1.0)将输出1.000000e+000,这是不正确的。C要求如果指数只能用一个或两个数字表示,那么只能打印两个数字。
在Visual Studio 2005中添加了一个全局一致性开关:_set_output_format。程序可以使用参数_TWO_DIGIT_EXPONENT调用此函数,以启用符合标准的指数打印。默认行为已更改为符合标准的指数打印模式。
#include <stdio.h>
int main(void) {
printf("%E\n", 5200000.0);
_set_output_format(_TWO_DIGIT_EXPONENT);
printf("%E\n", 5200000.0);
return 0;
}
|