Format Printing

From Progzoo
Revision as of 14:45, 16 October 2008 by Andr3w (talk | contribs) (New page: We can format output involving fixed and variable components. Usually we align strings to the left and numebrs to the right. ==== <question xmlns:htm="http://www.w3.org/1999/xhtml" lang="j...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

We can format output involving fixed and variable components. Usually we align strings to the left and numebrs to the right.

==

In the printf a number of values may follow the format string. These values are used up by % placeholders in the format string.

The format string is

"Country: %-18s GDP: %,20d\n"

%-18s
the minus in -18 means align left,

the 18 means 18 characters are to be used, the s is for string.

%,20d
the comma means include , separator every three digits, the 20

means use 20 characters and align right, d is for decimal.

\n::This starts a new line.
[Font] [Default] [Show] [Resize] [History] [Profile]