The format specification, which consists of optional and required fields, is shown here:
%[Flags][Width][.Precision]Type
Each field of the format specification is a character or a number which specifies a format option. The simplest format specification contains only the percent sign and a type character, such as: %s. If a percent sign is followed by a character that has no meaning as a format field, that character is simply copied to the output. For example, to print a percent sign, enter %%.
The optional fields, which appear before the Type character, control other aspects of the formatting, as follows:
Enter s, f, or d for this export function.
Use these flags to control justification of the output and the printing of signs, blanks, decimal points, and octal and hexadecimal prefixes. More than one flag can appear in a format specification.
Flag |
Description |
Default |
– |
Left aligns the result within the given field width. |
Right align. |
+ |
Prefixes the output value with a sign (+ or –) if the output value is of a signed type. |
Sign appears only for negative signed values (–). |
0 |
Adds zeros until the minimum width is reached. If a zero and a minus appear (-0), the system ignores the zero. If you include a zero with an integer format (d), the system ignores the zero flag. |
No padding. |
blank (' ') |
Prefixes the output value with a blank if the output value is signed and positive; the blank is ignored if both the blank and + flags appear. |
No blank appears. |
# |
When used with the f format, the # flag forces the output value to contain a decimal point in all cases. |
Decimal point appears only if digits follow it. |
Here you can control the minimum number of characters printed. If the number of characters in the output value is less than the width you specify, the system adds blanks to the left or the right of the values — depending on whether the flag for left alignment is specified — until the minimum width is reached. If you prefix the width with a zero (0), the system adds zeros until the minimum width is reached (not useful for left-aligned numbers).
Your entry for width never causes a value to be truncated. If the number of characters in the output value is greater than the width you specify, or if you omit the width, all characters of the value are printed (subject to the .Precision specification).
This optional number specifies the maximum number of characters printed for all or part of the output field, or the minimum number of digits printed for integer values.
For format s, the precision specifies the maximum number of characters to print. Characters in excess of precision are not printed. Characters are printed until a null character is encountered.
For format f, the precision specifies the number of digits after the decimal point. If a decimal point appears, at least one digit appears before it. The value is rounded to the appropriate number of digits. The default precision is six (6); if the precision is zero (0), or if a period (.) appears without a number following it, no decimal point is printed.
For format d, the precision specifies the minimum number of digits to be printed. If the number of digits in the argument is less than the precision value, the output value is padded on the left with zeros. The value is not truncated when the number of digits exceeds the precision. The default precision is one (1).
© Copyright 2013, Oracle and/or its affiliates. All rights reserved. Legal notices.