<html lang="en"> <head> <title>Output Conversion Syntax - Untitled</title> <meta http-equiv="Content-Type" content="text/html"> <meta name="description" content="Untitled"> <meta name="generator" content="makeinfo 4.13"> <link title="Top" rel="start" href="index.html#Top"> <link rel="up" href="C_002dStyle-I_002fO-Functions.html#C_002dStyle-I_002fO-Functions" title="C-Style I/O Functions"> <link rel="prev" href="Output-Conversion-for-Matrices.html#Output-Conversion-for-Matrices" title="Output Conversion for Matrices"> <link rel="next" href="Table-of-Output-Conversions.html#Table-of-Output-Conversions" title="Table of Output Conversions"> <link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage"> <meta http-equiv="Content-Style-Type" content="text/css"> <style type="text/css"><!-- pre.display { font-family:inherit } pre.format { font-family:inherit } pre.smalldisplay { font-family:inherit; font-size:smaller } pre.smallformat { font-family:inherit; font-size:smaller } pre.smallexample { font-size:smaller } pre.smalllisp { font-size:smaller } span.sc { font-variant:small-caps } span.roman { font-family:serif; font-weight:normal; } span.sansserif { font-family:sans-serif; font-weight:normal; } --></style> </head> <body> <div class="node"> <a name="Output-Conversion-Syntax"></a> <p> Next: <a rel="next" accesskey="n" href="Table-of-Output-Conversions.html#Table-of-Output-Conversions">Table of Output Conversions</a>, Previous: <a rel="previous" accesskey="p" href="Output-Conversion-for-Matrices.html#Output-Conversion-for-Matrices">Output Conversion for Matrices</a>, Up: <a rel="up" accesskey="u" href="C_002dStyle-I_002fO-Functions.html#C_002dStyle-I_002fO-Functions">C-Style I/O Functions</a> <hr> </div> <h4 class="subsection">14.2.6 Output Conversion Syntax</h4> <p>This section provides details about the precise syntax of conversion specifications that can appear in a <code>printf</code> template string. <p>Characters in the template string that are not part of a conversion specification are printed as-is to the output stream. <p>The conversion specifications in a <code>printf</code> template string have the general form: <pre class="example"> % <var>flags</var> <var>width</var> <span class="roman">[</span> . <var>precision</var> <span class="roman">]</span> <var>type</var> <var>conversion</var> </pre> <p>For example, in the conversion specifier ‘<samp><span class="samp">%-10.8ld</span></samp>’, the ‘<samp><span class="samp">-</span></samp>’ is a flag, ‘<samp><span class="samp">10</span></samp>’ specifies the field width, the precision is ‘<samp><span class="samp">8</span></samp>’, the letter ‘<samp><span class="samp">l</span></samp>’ is a type modifier, and ‘<samp><span class="samp">d</span></samp>’ specifies the conversion style. (This particular type specifier says to print a numeric argument in decimal notation, with a minimum of 8 digits left-justified in a field at least 10 characters wide.) <p>In more detail, output conversion specifications consist of an initial ‘<samp><span class="samp">%</span></samp>’ character followed in sequence by: <ul> <li>Zero or more <dfn>flag characters</dfn> that modify the normal behavior of the conversion specification. <a name="index-flag-character-_0028_0040code_007bprintf_007d_0029-785"></a> <li>An optional decimal integer specifying the <dfn>minimum field width</dfn>. If the normal conversion produces fewer characters than this, the field is padded with spaces to the specified width. This is a <em>minimum</em> value; if the normal conversion produces more characters than this, the field is <em>not</em> truncated. Normally, the output is right-justified within the field. <a name="index-minimum-field-width-_0028_0040code_007bprintf_007d_0029-786"></a> You can also specify a field width of ‘<samp><span class="samp">*</span></samp>’. This means that the next argument in the argument list (before the actual value to be printed) is used as the field width. The value is rounded to the nearest integer. If the value is negative, this means to set the ‘<samp><span class="samp">-</span></samp>’ flag (see below) and to use the absolute value as the field width. <li>An optional <dfn>precision</dfn> to specify the number of digits to be written for the numeric conversions. If the precision is specified, it consists of a period (‘<samp><span class="samp">.</span></samp>’) followed optionally by a decimal integer (which defaults to zero if omitted). <a name="index-precision-_0028_0040code_007bprintf_007d_0029-787"></a> You can also specify a precision of ‘<samp><span class="samp">*</span></samp>’. This means that the next argument in the argument list (before the actual value to be printed) is used as the precision. The value must be an integer, and is ignored if it is negative. <li>An optional <dfn>type modifier character</dfn>. This character is ignored by Octave's <code>printf</code> function, but is recognized to provide compatibility with the C language <code>printf</code>. <li>A character that specifies the conversion to be applied. </ul> <p>The exact options that are permitted and how they are interpreted vary between the different conversion specifiers. See the descriptions of the individual conversions for information about the particular options that they use. </body></html>