Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Format Strings

Note
For Refer to the Date Format String see this topic : DateTime Format Strings topic for specific data\time formatting options.

Format strings specify required formats to are the syntax for general-purpose formatting routines. Format strings passed to the string formatting routines contain two types of objects--literal characters and format ;

  • Literal characters, and
  • Format specifiers.

Literal characters are copied word for word to the resulting string. Format specifiers fetch arguments from the argument list and apply the formatting to them.

Format specifiers have the following form:

"%" [index ":"] ["-"] [width] ["." prec] type

A format specifier begins with a % character. After the percent sign come the following elements, in this order:

  1. An [index ":"] - An optional argument zero-offset index specifier (that is, the first item has index 0), .

  2. [index ":-"] .An - An optional left justification indicator, .

  3. ["-"].An width] - An optional width specifier, [width].

  4. An optional precision specifier, ["." prec] - An optional precision specifier.

  5. type - The conversion type character, type.

The following table summarizes the possible values for type.

...

Index, width, and precision specifiers can be specified directly, using a decimal digit string (for example "%10d"). Width is an integer value, while precision is an unsigned integer value. For example,

Format ('%8.2f', [123.456]);

A width specifier sets the minimum field width for a conversion. If the resulting string is shorter than the minimum field width, it is padded with blanks to increase the field width. The default is to right-justify the result by adding blanks in front of the value, but if the format specifier contains a left-justification indicator (an "-" en dash character preceding the width specifier), the result is left-justified by adding blanks after the value.

...