## • Format by specification

Two-argument form See also one-argument form Format

The right argument must be either a simple array, or have a maximum depth of 2 (no element higher rank than a vector).

Like the one-argument form, this version of • also converts numeric data to characters. The right argument is formatted according to the instructions in the left argument which is a integer scalar or vector. These instructions specify the width of each field in characters, and the number of decimal places to be displayed. If necessary, numbers are rounded in order to display them in the positions available.

If the first number in the left argument is 0, the system uses the specified number of decimal places, and as many other characters as are needed. If a single number is used for the left argument, it is treated as two numbers with the first set to 0.

Scaled (or scientific) notation can be forced if the second number of a pair of numbers in the left argument is negative. In this case, the negative number specifies the number of digits before the E character.

To display each number on the right in a field which is 10 characters wide and has 2 decimal places:

                 10 2 • 13.8765390 6 87.213 23.1
           13.88     6.00      87.21     23.10

                 TABLE
           2.77       1.731     22.9
           11         0.3301    2.3

To display each column in TABLE as a 5-character field with no decimal places:

                 5 0 • TABLE
            3   2    23
           11   0     2

To force scaled notation:

                 8 ¯2 • 7.1
           7.1E000

To specify the number of decimal places while allowing the rest of the number as many character positions as it needs (including one leading space):

                 0 2 • 22.1987 999.1
           22.20 999.10

                 ½ 0 2 • 11.7            (Asks the size of the formatted number.
           6                              It has been allocated 2 positions after
                                          the point, plus the 4 positions needed
                                          for the 2 integers, the point itself
                                          and a leading space)

Note: the above examples show a single pair of numbers in the left argument being applied in turn to each number in the right argument. The left argument can instead contain a separate pair of numbers (ie separate instructions) for each term on the right.

                 10 2 8 3 • 279.5547 10.1234
           279.55     10.123

### Using ŒFC with format by specification

Certain elements in the system variable ŒFC Format Control can influence the display generated by • when acting as 'format by specification'. In index origin 1:

ŒFC[1] specifies the character used for the decimal point. (. by default).

ŒFC[4] specifies the overflow character used for numbers too wide for the column width specified. (0 by default, causing a `DOMAIN ERROR` on overflow).

ŒFC[6] specifies the negative number indicator. (¯ by default).

                 ŒFC
           ,,*0_¯                        (Default settings)

                 5 3•1000                (DOMAIN ERROR for overflow by default)
           DOMAIN ERROR
                 5 3•1000
                 ^
                 ŒFC[4]„'*'
                 5 3•1000                (Alternative overflow character)
           *****
                 ŒFC[1]„','
                 10 3•12.15
               12,150
                 ŒFC[6]„'/'              (Change negative number indicator)
                 10 3•¯12.15
              /12,150

Topic: APLX Help : Help on APL language : APL Primitives : • Format by specification

[ Previous | Next | Contents | Index ]