A format specification, which consists of optional and required fields, has the following form:

% [flags] [width] [.precision] [type]

Each conversion specification starts with the percent % character. Each field of the format specification is a character or a number that signifies a particular format option or conversion specifier. The required type character specifies the kind of conversion to be applied to an argument. The optional flags, width, and precision fields control additional format aspects. A basic format specification contains only the percent sign and a type character—for example, %s. If a percent sign is followed by a character that has no meaning as a format field, the character is copied to the output string unchanged. To print a percent-sign character, use %%.

The fields of the format specification control the following aspects of argument conversion and formatting:

flags

Optional character or characters that control output justification and output of signs, blanks, leading zeros, decimal points, and octal and hexadecimal prefixes. For more information, see Flag Directives. More than one flag can appear in a format specification, and flags can appear in any order.

width

Optional decimal number that specifies the minimum number of characters that are output. For more information, see Width Specification.

.precision

Optional decimal number that specifies the maximum number of characters that are printed for strings, the number of significant digits or the number of digits after the decimal-point character for floating-point values, or the minimum number of digits that are printed for integer values. For more information, see Precision Specification.

If an argument corresponding to a floating point data is infinite, indefinite or NAN, the output of the function is given in the following table:

Valore

Risultato

+ infinity

1.#INFrandom-digits

– infinity

–1.#INFrandom-digits

Indefinite

digit.#INDrandom-digits

NAN

digit.#NANrandom-digits