The new home for Visual Studio documentation is Visual Studio 2017 Documentation on docs.microsoft.com.
The latest version of this topic can be found at Visual Studio 2017 Documentation. In a format specification, the third optional field is the precision specification. It consists of a period (.) followed by a non-negative decimal integer that, depending on the conversion type, specifies the number of string characters, the number of decimal places, or the number of significant digits to be output.
Unlike the width specification, the precision specification can cause either truncation of the output value or rounding of a floating-point value. If
precision is specified as 0 and the value to be converted is 0, the result is no characters output, as shown in this example:
printf( "%.0d", 0 ); /* No characters output */
If the precision specification is an asterisk (*), an
int argument from the argument list supplies the value. In the argument list, the
precision argument must precede the value that's being formatted, as shown in this example:
printf( "%.*f", 3, 3.14159265 ); /* 3.142 output */
The type determines either the interpretation of
precision or the default precision when
precision is omitted, as shown in the following table.
How Precision Values Affect Type
||The precision specifies the number of digits after the point.||Default precision is 6. If precision is 0, no decimal point is printed unless the
||The precision has no effect.||Character is printed.|
||The precision specifies the minimum number of digits to be printed. If the number of digits in the argument is less than
||Default precision is 1.|
||The precision specifies the number of digits to be printed after the decimal point. The last printed digit is rounded.||Default precision is 6. If
||The precision value specifies the number of digits after the decimal point. If a decimal point appears, at least one digit appears before it. The value is rounded to the appropriate number of digits.||Default precision is 6. If
||The precision specifies the maximum number of significant digits printed.||Six significant digits are printed, and any trailing zeros are truncated.|
||The precision specifies the maximum number of characters to be printed. Characters in excess of
||Characters are printed until a null character is encountered.|