<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <!-- Created by GNU Texinfo 6.5, http://www.gnu.org/software/texinfo/ --> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>Output Conversion Syntax (GNU Octave (version 5.1.0))</title> <meta name="description" content="Output Conversion Syntax (GNU Octave (version 5.1.0))"> <meta name="keywords" content="Output Conversion Syntax (GNU Octave (version 5.1.0))"> <meta name="resource-type" content="document"> <meta name="distribution" content="global"> <meta name="Generator" content="makeinfo"> <link href="index.html#Top" rel="start" title="Top"> <link href="Concept-Index.html#Concept-Index" rel="index" title="Concept Index"> <link href="index.html#SEC_Contents" rel="contents" title="Table of Contents"> <link href="C_002dStyle-I_002fO-Functions.html#C_002dStyle-I_002fO-Functions" rel="up" title="C-Style I/O Functions"> <link href="Table-of-Output-Conversions.html#Table-of-Output-Conversions" rel="next" title="Table of Output Conversions"> <link href="Output-Conversion-for-Matrices.html#Output-Conversion-for-Matrices" rel="prev" title="Output Conversion for Matrices"> <style type="text/css"> <!-- a.summary-letter {text-decoration: none} blockquote.indentedblock {margin-right: 0em} blockquote.smallindentedblock {margin-right: 0em; font-size: smaller} blockquote.smallquotation {font-size: smaller} div.display {margin-left: 3.2em} div.example {margin-left: 3.2em} div.lisp {margin-left: 3.2em} div.smalldisplay {margin-left: 3.2em} div.smallexample {margin-left: 3.2em} div.smalllisp {margin-left: 3.2em} kbd {font-style: oblique} pre.display {font-family: inherit} pre.format {font-family: inherit} pre.menu-comment {font-family: serif} pre.menu-preformatted {font-family: serif} pre.smalldisplay {font-family: inherit; font-size: smaller} pre.smallexample {font-size: smaller} pre.smallformat {font-family: inherit; font-size: smaller} pre.smalllisp {font-size: smaller} span.nolinebreak {white-space: nowrap} span.roman {font-family: initial; font-weight: normal} span.sansserif {font-family: sans-serif; font-weight: normal} ul.no-bullet {list-style: none} --> </style> <link rel="stylesheet" type="text/css" href="octave.css"> </head> <body lang="en"> <a name="Output-Conversion-Syntax"></a> <div class="header"> <p> Next: <a href="Table-of-Output-Conversions.html#Table-of-Output-Conversions" accesskey="n" rel="next">Table of Output Conversions</a>, Previous: <a href="Output-Conversion-for-Matrices.html#Output-Conversion-for-Matrices" accesskey="p" rel="prev">Output Conversion for Matrices</a>, Up: <a href="C_002dStyle-I_002fO-Functions.html#C_002dStyle-I_002fO-Functions" accesskey="u" rel="up">C-Style I/O Functions</a> [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Concept-Index.html#Concept-Index" title="Index" rel="index">Index</a>]</p> </div> <hr> <a name="Output-Conversion-Syntax-1"></a> <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> <p>Characters in the template string that are not part of a conversion specification are printed as-is to the output stream. </p> <p>The conversion specifications in a <code>printf</code> template string have the general form: </p> <div class="example"> <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></div> <p>For example, in the conversion specifier ‘<samp>%-10.8ld</samp>’, the ‘<samp>-</samp>’ is a flag, ‘<samp>10</samp>’ specifies the field width, the precision is ‘<samp>8</samp>’, the letter ‘<samp>l</samp>’ is a type modifier, and ‘<samp>d</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> <p>In more detail, output conversion specifications consist of an initial ‘<samp>%</samp>’ character followed in sequence by: </p> <ul> <li> Zero or more <em>flag characters</em> that modify the normal behavior of the conversion specification. <a name="index-flag-character-_0028printf_0029"></a> </li><li> An optional decimal integer specifying the <em>minimum field width</em>. 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-_0028printf_0029"></a> <p>You can also specify a field width of ‘<samp>*</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>-</samp>’ flag (see below) and to use the absolute value as the field width. </p> </li><li> An optional <em>precision</em> to specify the number of digits to be written for the numeric conversions. If the precision is specified, it consists of a period (‘<samp>.</samp>’) followed optionally by a decimal integer (which defaults to zero if omitted). <a name="index-precision-_0028printf_0029"></a> <p>You can also specify a precision of ‘<samp>*</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. </p> </li><li> An optional <em>type modifier character</em>. 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><li> A character that specifies the conversion to be applied. </li></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. </p> <hr> <div class="header"> <p> Next: <a href="Table-of-Output-Conversions.html#Table-of-Output-Conversions" accesskey="n" rel="next">Table of Output Conversions</a>, Previous: <a href="Output-Conversion-for-Matrices.html#Output-Conversion-for-Matrices" accesskey="p" rel="prev">Output Conversion for Matrices</a>, Up: <a href="C_002dStyle-I_002fO-Functions.html#C_002dStyle-I_002fO-Functions" accesskey="u" rel="up">C-Style I/O Functions</a> [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Concept-Index.html#Concept-Index" title="Index" rel="index">Index</a>]</p> </div> </body> </html>