Two-argument form See also one-argument form Format
The right argument must be a simple numeric array.
Like the one-argument form, this version of
The left argument can either be one field, in which case that field is used to format each element or column of the right argument, or a series of fields to be applied, one to each column of the right argument. Numbers will be rounded to fit into their formatted layout.
A field is made up of characters drawn from the characters '0123456789' and . (full stop),
In common with other formatters, format by example permits decorator characters to:
The standard character used for format by example fields is 5, which is used to indicate simple formatting with removal of leading zeroes and suppression of trailing blanks. Zero values print as blanks.
'55.55' ⍕22.234 1.398 11.00 22.23 1.4 11 (Trailing blanks in 11 suppressed) '55.55 5.555 55.55 55'⍕22.234 1.398 0.00 11.0 22.23 1.398 11 (0 prints as blank) '555,555,555.55'⍕1234567.89 1,234,567.89 (The , only appears between digits, leading blanks are suppressed)
The control character 5 does not print positive or negative indicators (+ or -) and indeed will not accept negative numbers.
'55.55'⍕ ¯10 DOMAIN ERROR '55.55'⍕¯10 ^
Decorator characters which appear at the beginning or end of a field specification without special control characters will print where they appear in the left argument, they will not float.
' SALARY IS : $555,555,555.00' ⍕ 1234567.95 SALARY IS : $ 1,234,567.95 ($ decorator does not float)
Negative numbers and floating decorators
The field control characters 1 and 2 should be used if negative numbers are likely to be found in the right argument of
'¯155.55' ⍕10.1 ¯12.346 11.5 10.1 ¯12.35 11.5 (Negative numbers with high-minus) '(155.55)' ⍕10.1 ¯12.346 11.5 10.1 (12.35) 11.5 (Negative numbers in brackets) ⍴'(155.55)'⍕10.1 ¯12.345 11.5 24 (Overall field size is the same, floated characters which do not appear are replaced by spaces) '+255,555,555.55'⍕ ¯101.34 1000234 13.1 101.34 +1,000,234 +13.1
The control character 3 will purely float a decorator against a number being formatted, and will not accept negative numbers.
'THE BALANCE IS : $555,555.55' ⍕ 10027.34 THE BALANCE IS : $ 10,027.34 'THE BALANCE IS : $555,555.53' ⍕ 10027.34 THE BALANCE IS : $10,027.34
In the example above the currency sign is floated against the amount. Note that the overall field length is the same and that decorators which are not next to the field specification do not float .
If the control characters 1, 2 or 3 appear in a field specification on their own they will apply to the decorators on both sides of the field. If two of these characters appear in a field specification, then each will apply to the decorators on its side of the number. In the example below, 1 acts with the minus sign on the left, 2 acts with the characters CR on the right.
'-155,555.52CR'⍕ 101.34 ¯1000.29 15367.346 101.34CR -1,000.29 15,367.35CR
Finally, the control character 4 can be used to switch off the effect of the control characters 1, 2 or 3. In the example below, the 4 switches off the effect of the 1 such that, on the right of the numbers, the characters DEG always appear.
'-154.5DEG ' ⍕95.8 32.5 ¯27.2 95.8DEG 32.5DEG -27.2DEG
Contrast the effect when the character 4 is omitted
'-155.5DEG '⍕95.8 32.5 ¯27.2 95.8 32.5 -27.2DEG
In this example, the characters DEG print when the number is negative, under the control of the character 1.
Leading and trailing zeroes
The printing of leading and trailing zeroes can be forced by the control characters 0 and 9. One of these control characters placed in a field will indicate that 0s should be used up to that position. The effect of the 0 and 9 only differs in their treatment of the number 0. Control character 0 will print the appropriate number of 0s, control character 9 will use blanks.
'55.55 '⍕21.1 27.25 33 21.1 27.25 33 (Trailing zeroes suppressed) '55.50 '⍕21.1 27.25 33 21.10 27.25 33.00 (Always print to two decimal places) '55.5055 '⍕21.1 27.12345 33 21.10 27.1235 33.00 (0 only forces printing of zero up to its position in the field) '55.00 '⍕21.1 0 33 21.10 .00 33.00 (Control character 0 prints value 0) '55.59 '⍕21.1 0 33 21.10 33.00 (Control character 9 does not) '055,555.50' ⍕ 1000.1 001,000.10 (Leading zeroes forced)
Control character 8 fills empty portions of a field with the contents of
'TOTAL AMOUNT $385,555,555.00'⍕1000 TOTAL AMOUNT $******1,000.00
Alternative end of field delimiter and blanks within numbers
It is sometimes useful to format numbers with no spaces between them. This may be achieved by use of control character 6 which can be used to mark the end of a field.
'5556/06/05 '⍕3↑⎕TS (Three fields in left argument to ⍕) 1991/06/14
Contrast the example above with the next example which inserts a decorator within a number being formatted.
'0555/55/55 '⍕19910614 (Only one field in left argument to ⍕) 1991/06/14
The 'print-as-blank' character
'5.555_555_555_555_555 '⍕ ○1 3.141 592 653 589 790
Copyright © 1996-2010 MicroAPL Ltd