浮点值的格式说明符的一般形式如下:

%[width][.precision][modifier]f

方括号代表可选规范。
可以省略width.precisionmodifier或这些的任意组合。
width值是一个整数,指定包含空格的字符总数。precision值是一个整数,指定小数点后的小数位数。
当输出的值是long double类型时,修饰符部分为L,否则省略它。

#include <stdio.h>

int main(void)
{
  float total_length = 10.0f;               // In feet
  float count = 4.0f;                 // Number of equal pieces
  float piece_length = 0.0f;                // Length of a piece in feet
  piece_length = total_length/count;

  printf("%f feet %f pieces %f feet.\n",total_length, count, piece_length);

  printf("%8.2f foot %5.0f pieces %6.2f feet.\n",total_length, count, piece_length);
  return 0;
}