The function _fmt transforms character and numeric data in x into a character table according to specification y, which consist of a series of format phrases - see the "Format Phrases" table - separated by commas. For example, the string 'i6,f8.2,f6.1' contains three phrases. Each phrase governs the appearance of a column in the result. The number of phrases need not match the number of items in x, the phrases being repeated cyclically as needed; furthermore, tab and constant specifications are in separate phrases.
Each phrase has a type, indicated by a letter, such as the letters i and f in the above example. A tab or constant field in y does not correspond to anything in x. A tab field merely contributes to the positioning of the next part of the output, and a constant field is reproduced in the output exactly as shown.
Within each format phrase, to the left of the letter that identifies its type, qualifiers or decorators may be inserted. A qualifier provides additional rules, such as "insert commas between triplets of digits" or "leave this field blank for zero". See the "Qualifiers" table. A decorator is a code letter immediately followed by a piece of text enclosed in angle brackets or whatnot; the text is to be attached to the representation of a number, usually to indicate its sign. See the "Decorators" table.
When rounding is required, IEEE rules are used: see "Format". When a number cannot be formatted in the specified manner, its field is filled with asterisks. A field whose format is valid but for a different type from the data is filled with question marks. In particular, symbols in x do not cause an error message, but the field in which a symbol is to be formatted is filled with question marks.
Normally, x is a matrix, and the application of the formatting phrases is straightforward. It can be of other ranks and of any depth, however. In that case, the columns to be formatted are obtained, conceptually, by the following process. When a nested array is encountered, it is ravelled, and its elements are successively disclosed and treated in the manner being described. When a simple array is encountered, it is transformed into a matrix if it is not already one: a scalar becomes a 1 by 1 matrix, an n-element vector becomes an n by 1 matrix, and any other array a is reshaped as ((«/¢1ÕÒa),¢1ÙÒa)Òa. This produces a series of matrices, and thus a series of columns, to which the formatting phrases are applied as stated above. Each formatted column can be viewed as a character matrix; the result has the same number of rows as the one with the most rows. Conceptually, blank rows are appended as necessary to each of these matrices to make them the same length as the result, and they are catenated side by side (,@0) to form the result.
In the "Format Phrases" table, j is an optional repetition factor; q represents an optional qualifier and decorators; w is field width; d denotes significant digits or decimal digits; p is displacement; a, e, f, i, t, and x are literals giving phrase types.
Format Phrases
Phrase | Application | Description |
jaw |
Character |
Display each character in a field w positions wide. A w greater
than 1 produces blanks between adjacent characters. |
jqew.d |
Exponential |
Display each number in a field w positions wide, with d significant
digits. Align E's and decimal points in fields that are not left
justified. |
jqfw.d |
Fixed point |
Display in a field w positions wide, with d decimal digits, including
trailing zeros. Leading zeros are shown as blanks unless the z qualifier is
used. |
jqiw | Integer |
Display in a field w positions wide. Leading zeros are shown as blanks unless
the z qualifier is used. |
jqg<txt> |
Picture Format, rounding arguments to integers |
In txt, 9 and z are "special characters"; the rest are
"ordinary." Round each number to an integer, after scaling if k is present.
If s is present, modify txt as required. Then format each number with as many
digits as there are special characters in txt, so each digit corresponds to a
special character. Display a digit corresponding to a 9 unconditionally. If
a digit corresponding to a z is in a sequence of leading or trailing zeros,
display a blank; otherwise, display the digit. Display ordinary characters as is, with
one exception, intended to exclude superfluous thousands separators but include decimal
points: any ordinary character surrounded by special characters is displayed as blank
if in the display a blank is next to it, unless it is the last ordinary character
and is followed by at most two characters. The only valid decorators and qualifiers are
m and p (but only the first character of the text of each), s,
and k. |
jtp | Absolute tab |
Start the next field at position p+1. If p is too small, the next field
may overwrite earlier ones. |
jxp | Relative tab |
Start the next field at a position displaced p positions from the end of the
preceding field. If p is negative, the next field may overwrite earlier
ones. |
<text> | Constant: for all |
Insert text in every row of the result. |
Qualifiers
Qualifier | Summary | Description |
b | blanks |
Make the entire field blank when the value is zero. |
c | commas |
Insert commas between successive triplets of digits in integer and (before the
decimal point) fixed-point fields. |
ke | scale |
Scale the result by displaying a value that is 10e times
the value. |
l | justify |
Left justify. The default is right justification. |
z | zeros |
Display leading zeroes in integer and fixed-point fields. |
In the "Decorators" table, text may also be delimited by ¤¦, ÚØ, ¡¡, //, ÌÌ, ìì.
Decorators
Decorator | Summary | Description |
m<text> | Negative-Left |
Insert text to the left of a negative value, not APL high minus. text
can be empty. m and n can be used together. |
n<text> | Negative-Right |
Insert text to the right of a negative value rather than use APL high minus.
text can be empty. m and n can be used together. |
o<text> | Zero replacement |
When the data as formatted is zero, replace the result by text. Valid for the
e, f, and i phrase types. |
p<text> | Positive-Left |
Insert text to the left of a positive value. p and q can be
used together. |
q<text> | Positive-Right |
Insert text to the right of a positive value. p and q can be
used together. |
r<text> | Background |
Fill the field cyclically with text where normally blanks would appear,
including blanks from a b qualifier. For e, f, and i
phrase types. |
s<text> | Symbol Substitution |
For each pair of characters in text, the second indicates a character to replace
the first. In e, f, and i phrase types, punctuation, sign, and
error characters in the result can be replaced; in a g phrase type, any
characters in the picture text and error characters in the result can be replaced; no
other replacements can be made. For example, s<,..,> in an f
phrase type produces periods where commas usually appear and commas where periods usually
appear. |
'e9.4' _fmt 200 .987
2.000E 2 ã Internal blank used to align decimal points and E's.
9.870E¢1
nû123456789 0 ¢123456789 123456
'bcm<->k-2f13.2' _fmt n
1,234,567.89
-1,234,567.89
1,234.56
'm<(> n<)> q< > b c k-2 f16.2' _fmt n
1,234,567.89 ã Blanks are okay in the left argument.
(1,234,567.89)
1,234.56
'i 6' _fmt `wrong `type
??????
??????
'g<99:99:99>' _fmt 100Â3Ù3Õsys.ts{}
07:19:30
'g<zz9>' _fmt .49 .51 99.47
0
1
99
rfndû 1.23 10.00 12345.67 332 1234.56
'k2 g<Your refund is: $z,zz9.99>' _fmt rfnd
Your refund is: $ 1.23 ã k2 applied to 1.23 is 123, and the
Your refund is: $ 10.00 ã decimal point in 1.23 is from g.
************************* ã 12,345.67 is too long; if we had s<*?>
Your refund is: $ 332.00 ã in the left arg, *...* would be ?...?.
Your refund is: $1,234.56 ã The comma is needed here, and it appears.
'k2 g<Your refund is: $z,zz9.zz>' _fmt 1.23 10.00
Your refund is: $ 1.23
Your refund is: $ 10. ã The decimal point is the last ordinary
ã character and it has only two characters
ã after it,so it's shown even when the
ã trailing zeros are dropped.
's<9#z$>g<$$$# units of product z9>' _fmt 73
73 units of product z9 ã s allows 9 and z to be included literally
ã in the output.