APLX Help : Help on APL language : APL Fundamentals : Formatting


Formatting 

The default way in which APL displays results may not always suit your requirements. Obviously you can do a certain amount by using functions like size to reshape data, or catenate to join data items, but for many applications you may want much more sophisticated facilities. You may, for example, want to insert currency signs and spaces in numeric output, or produce a neatly formatted financial report, or specify precisely the format in which numbers are displayed. APLX has a variety of functions for formatting data, providing flexibility as well as compatibility with a number of other APL interpreters. Formatting functionsThere are three functions in APLX which all convert the format of data from numbers to characters, and allow you to specify how the converted numeric data should be laid out. The functions are:
Each function lets you specify how many character positions a number should occupy when it is displayed, and how many of these positions are available for decimal places. The number of characters and number of decimal places are specified in the left argument: 6 2 ⍕ 1341.82921 341.83 (Note that since the number had to be truncated to fit the character positions allowed, it was first rounded to make the truncated representation as accurate as possible.) Picture format ( The following example shows the values in a 4row 2column matrix called TAB 1096.2 ¯416.556 296.974 1085.238 ¯811.188 844.074 ¯745.416 153.468 '$$Z,ZZ9.99 DR ' ⍺ TAB $1,096.20 $416.56 DR $296.97 $1,085.24 $811.19 DR $844.07 $745.42 DR $153.47
'B K2 G< ZZ9 DOLLARS AND 99 CENTS>' ⎕FMT 8.23 12.86 0 2.52 8 DOLLARS AND 23 CENTS 12 DOLLARS AND 86 CENTS 2 DOLLARS AND 52 CENTS 

APLX Help : Help on APL language : APL Fundamentals : Formatting

Copyright © 19962010 MicroAPL Ltd