printf() Default Floating-Point Precision Is 6 Decimals

已弃用知识库内容免责声明

本文介绍 Microsoft 不再提供支持的产品。 因此,本文“按原样”提供,并且不再更新。

Summary

By default, the printf() function displays a floating-point number to six digits of precision. This default also holds for double precision numbers.


To display additional digits of precision, specify a value for the precision field in the printf() format specification, as follows:
%[<flags>][<width>][.<precision>]<type>

More Information

The code example below demonstrates documented printf() behavior that may appear to be a problem with the function.

   #include <stdio.h>

main()
{
double d = 1.2345678912;

printf("%e\n", d);
printf("%le\n", d);
}
This code example produces the following output:



1.234568e+000
1.234568e+000
To display the value d to its full precision, modify the code example to use the following statement:
   printf("%.15le", d);
属性

文章 ID:29557 - 上次审阅时间:2003年12月11日 - 修订版本: 1

反馈