Skip to main content
Engineering LibreTexts

10.2: Format Specifiers

  • Page ID
    54286
  • \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \) \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)\(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\) \(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\)\(\newcommand{\AA}{\unicode[.8,0]{x212B}}\)

    The format specifiers tell the system exactly how the input or output should be handled. Each value being read or written requires some amount of space. For example, an integer of four digits requires at least four spaces or positions to print. Therefore, the number of positions to be used is a key part of the specifier.

    The following convention of symbols:

    • \(w\): the number of positions to be used
    • \(m\): the minimum number of positions to be used
    • \(d\): the number of digits to the right of the decimal point
    • \(n\): the number or count
    • \(c\): column number
    • \(r\): repeat count

    The following is a summary of the most commonly used format specifiers:

    Description Specifier
    Integers rIw or rIw.m
    Real rFw.d
    Logicals rLw
    Characters rA or rAw
    Horizontal Positioning (space) nX
    Horizontal Positioning (column) Tc
    Vertical Spacing n/

    In addition, each specifier or group of specifiers can be repeated by preceding it with a repeat count. Format specifiers for complex numbers will be addressed in later chapters.


    This page titled 10.2: Format Specifiers is shared under a CC BY-NC-SA 3.0 license and was authored, remixed, and/or curated by Ed Jorgensen via source content that was edited to the style and standards of the LibreTexts platform; a detailed edit history is available upon request.

    • Was this article helpful?