user-0 提问: printf（）；

回复:
user: user-1
content: 楼主为什么不自己试试呢，运行了就知道了

user: user-2
content: printf Width Specification The second optional field of the format specification is the width specification. The width argument is a nonnegative decimal integer controlling the minimum number of characters printed. If the number of characters in the output value is less than the specified width, blanks are added to the left or the right of the values — depending on whether the – flag (for left alignment) is specified — until the minimum width is reached. If width is prefixed with 0, zeros are added until the minimum width is reached (not useful for left-aligned numbers).  The width specification never causes a value to be truncated. If the number of characters in the output value is greater than the specified width, or if width is not given, all characters of the value are printed (subject to the precision specification).  If the width specification is an asterisk (*), an int argument from the argument list supplies the value. The width argument must precede the value being formatted in the argument list. A nonexistent or small field width does not cause the truncation of a field; if the result of a conversion is wider than the field width, the field expands to contain the conversion result. Precision Specification The third optional field of the format specification is the precision specification. It specifies a nonnegative decimal integer, preceded by a period (.), which specifies the number of characters to be printed, the number of decimal places, or the number of significant digits (see Table R.5). 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 below:  printf( "%.0d", 0 );      /* No characters output */  If the precision specification is an asterisk (*), an int argument from the argument list supplies the value. The precision argument must precede the value being formatted in the argument list.  The type determines the interpretation of precision and the default when precision is omitted, as shown in Table R.5.  Table R.5   How Precision Values Affect Type  Type Meaning Default  c, C The precision has no effect. Character is printed.  d, i, u, o, x, X The precision specifies the minimum number of digits to be printed. If the number of digits in the argument is less than precision, the output value is padded on the left with zeros. The value is not truncated when the number of digits exceeds precision. Default precision is 1.  e, E 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 precision is 0 or the period (.) appears without a number following it, no decimal point is printed.   f  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 precision is 0, or if the period (.) appears without a number following it, no decimal point is printed.  g, G The precision specifies the maximum number of significant digits printed. Six significant digits are printed, with any trailing zeros truncated.  s, S The precision specifies the maximum number of characters to be printed. Characters in excess of precision are not printed. Characters are printed until a null character is encountered.    If the argument corresponding to a floating-point specifier is infinite, indefinite, or NaN, printf gives the following output.  Value Output  + infinity 1.#INFrandom-digits  – infinity –1.#INFrandom-digits  Indefinite (same as quiet NaN) digit.#INDrandom-digits  NAN  digit.#NANrandom-digits

user: user-3
content: 引用 1 楼 user-9 的回复:%m.nf格式中m和n的关系应该是m>n+2,即没有整数部分的位置，也要考虑一个符号位和一个小数点位。你的%2.5f对编译器而言本来就是不合理要求，它只能按它能满足的某个功能：如保证值的正确性、保证值的有效宽度等----这些称作编译器的行为（实现的行为这个编译器的作者在满足ANSI C的大前提下，个别ANSI C没有严格限定的就按作者自己的意愿做了） 	y=333.1234567; 	printf("%8.5f\n",y); 这样的话  8>5+2 但结果显示为 333.12346 加上小说点是9位了。 这个也是属于相同意思的编译器行为吗？

user: user-4
content: 引用 1 楼 user-9 的回复:%m.nf格式中m和n的关系应该是m>n+2,即没有整数部分的位置，也要考虑一个符号位和一个小数点位。你的%2.5f对编译器而言本来就是不合理要求，它只能按它能满足的某个功能：如保证值的正确性、保证值的有效宽度等----这些称作编译器的行为（实现的行为这个编译器的作者在满足ANSI C的大前提下，个别ANSI C没有严格限定的就按作者自己的意愿做了） ++

user: user-5
content: 实际数值大于给定宽度，按实际输出！

user: user-6
content: 引用 3 楼 zxh707wk 的回复:引用 2 楼 turingo 的回复:++  [quote=引用 1 楼 user-9 的回复:] %m.nf格式中m和n的关系应该是m>n+2,即没有整数部分的位置，也要考虑一个符号位和一个小数点位。你的%2.5f对编译器而言本来就是不合理要求，它只能按它能满足的某个功能：如保证值的正确性、保证值的有效宽度等----这些称作编译器的行为（实现的行为这个编译器的作者在满足ANSI C的大前提下，个别ANSI C没有严格限定的就按作者自己的意愿做了） +1[/quote]  ++

user: user-7
content: 引用 2 楼 turingo 的回复:++  引用 1 楼 user-9 的回复:%m.nf格式中m和n的关系应该是m>n+2,即没有整数部分的位置，也要考虑一个符号位和一个小数点位。你的%2.5f对编译器而言本来就是不合理要求，它只能按它能满足的某个功能：如保证值的正确性、保证值的有效宽度等----这些称作编译器的行为（实现的行为这个编译器的作者在满足ANSI C的大前提下，个别ANSI C没有严格限定的就按作者自己的意愿做了） +1

user: user-8
content: ++  引用 1 楼 user-9 的回复:%m.nf格式中m和n的关系应该是m>n+2,即没有整数部分的位置，也要考虑一个符号位和一个小数点位。你的%2.5f对编译器而言本来就是不合理要求，它只能按它能满足的某个功能：如保证值的正确性、保证值的有效宽度等----这些称作编译器的行为（实现的行为这个编译器的作者在满足ANSI C的大前提下，个别ANSI C没有严格限定的就按作者自己的意愿做了）

user: user-9
content: %m.nf格式中m和n的关系应该是m>n+2,即没有整数部分的位置，也要考虑一个符号位和一个小数点位。你的%2.5f对编译器而言本来就是不合理要求，它只能按它能满足的某个功能：如保证值的正确性、保证值的有效宽度等----这些称作编译器的行为（实现的行为这个编译器的作者在满足ANSI C的大前提下，个别ANSI C没有严格限定的就按作者自己的意愿做了）