Go to the first, previous, next, last section, table of contents.


Format-Control Letters

A format specifier starts with the character `%' and ends with a format-control letter; it tells the printf statement how to output one item. (If you actually want to output a `%', write `%%'.) The format-control letter specifies what kind of value to print. The rest of the format specifier is made up of optional modifiers which are parameters such as the field width to use.

Here is a list of the format-control letters:

`c'
This prints a number as an ASCII character. Thus, `printf "%c", 65' outputs the letter `A'. The output for a string value is the first character of the string.
`d'
This prints a decimal integer.
`i'
This also prints a decimal integer.
`e'
This prints a number in scientific (exponential) notation. For example,
printf "%4.3e", 1950
prints `1.950e+03', with a total of four significant figures of which three follow the decimal point. The `4.3' are modifiers, discussed below.
`f'
This prints a number in floating point notation.
`g'
This prints a number in either scientific notation or floating point notation, whichever uses fewer characters.
`o'
This prints an unsigned octal integer.
`s'
This prints a string.
`x'
This prints an unsigned hexadecimal integer.
`X'
This prints an unsigned hexadecimal integer. However, for the values 10 through 15, it uses the letters `A' through `F' instead of `a' through `f'.
`%'
This isn't really a format-control letter, but it does have a meaning when used after a `%': the sequence `%%' outputs one `%'. It does not consume an argument.


Go to the first, previous, next, last section, table of contents.