In a format specification, the second optional field is the width specification. The width argument is a non-negative decimal integer that controls the minimum number of characters that are output. 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 left alignment flag (-) is specified—until the minimum width is reached. If width is prefixed by 0, leading zeros are added to integer or floating-point conversions until the minimum width is reached, except when conversion is to an infinity or NAN.

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 output, subject to the precision specification.

A missing or small width value in a format specification does not cause the truncation of an output value. If the result of a conversion is wider than the width value, the field expands to contain the conversion result.

Width Effects on output width
n At least n characters are printed; if the output value has less than n characters, it is aligned with spaces (to the right if the - flag is given, to the left otherwise).
0n At least n characters are printed; if the output value has less than n characters, it is filled with zeros on the left.

See also