A flag directive is a character that specifies output justification and output of signs, blanks, leading zeros, decimal points, and octal and hexadecimal prefixes. More than one flag directive may appear in a format specification, and flags can appear in any order.

Flag Meaning Default
- Left align the result within the given field width. Right align.
+ Use a sign (+ or –) to prefix the output value if it is of a signed type. Sign appears only for negative signed values (–).
blank (' ') Use a blank to prefix the output value if it is signed and positive. The blank is ignored if both the blank and + flags appear. No blank appears.
# When it's used with the o format, the # flag uses 0 to prefix any nonzero output value.  
When it's used with the x, or X format, the # flag uses 0x, or 0X, respectively, to prefix any nonzero output value.  
When it's used with the e, E, f, a or A format, the # flag forces the output value to contain a decimal point. Decimal point appears only if digits follow it.
When it's used with the g or G format, the # flag forces the output value to contain a decimal point and prevents the truncation of trailing zeros. Ignored when used with c, d, i, u, or s. Decimal point appears only if digits follow it. Trailing zeros are truncated.
0 If width is prefixed by 0, leading zeros are added until the minimum width is reached. If both 0 and – appear, the 0 is ignored. If 0 is specified as an integer format (i, u, x, X, o, d) and a precision specification is also present—for example, %04.d—the 0 is ignored. No padding.

The plus sign (+) takes precedence over the space if both are used.

See also