printf and sprintf format a list of values according to a format string that may use the following conversions:
| A percent sign. |
| An unsigned integer (binary). |
| The character corresponding to the ordinal value. |
| A signed integer. |
| A floating-point number (scientific notation). |
| A floating-point number (fixed decimal notation). |
| A floating-point number |
| A synonym for |
| The number of characters formatted so far is stored into the corresponding variable in the parameter list. |
| An unsigned integer (octal). |
| A pointer (address in hexadecimal). |
| A string. |
| An unsigned integer (decimal). |
| An unsigned integer (hexadecimal). |
| Like |
| An obsolete synonym for |
| Like |
| An obsolete synonym for |
| Like |
| An obsolete synonym for |
| An obsolete synonym for |
| Like |
The following flags can be put between the %
and the conversion letter:
space | Prefix a positive number with a space. |
| Prefix a positive number with a plus sign. |
| Left-align within the field. |
| Use zeros instead of spaces to right-align. |
| With |
number | Minimum field width. |
| For a floating-point number, the number of digits after the decimal point. For a string, the maximum length. For an integer, the minimum width. The integer will be right-aligned, padded with zeros. |
| Interpret integer as C type short or unsigned short. |
| Interpret integer as C type char. |
| |
| Interpret integer as C type long or unsigned long. |
| Interpret integer as C type quad (64-bit). |
| Interpret integer as C type ptrdiff_t. |
| Print string as series of ordinals. Use with |
| Interpret integer according to Perl’s type. |
| Interpret integer as C type size_t. |
An asterisk (*
) may be used instead of a number; the value of the next item in the list will be used. With %*v,
the next item in the list will be used to separate the values.
Parameter ordering can be obtained by inserting n$
directly after a %
or *
. This conversion will then use the nth argument.
See the section Formats below for an alternative way to obtain formatted output.