Fields - formats (numeric)¶
Contents
Numeric format templates¶
The formatting of numeric fields is done by reference to a template. A template is a precise map of the characters that are to appear in the output. The output width of the field is equal to the number of characters specified in the format template. The following characters have a special meaning:
# |
designates a position where leading zeros are to be space-filled |
0 |
designates a position where leading zeros are to be printed |
* |
designates a position where leading zeros are to be filled with asterisks |
, |
designates a comma to group significant digits |
. |
position of decimal point |
£ |
Leading pound |
$ |
Leading dollar |
A numeric format is processed from right to left. Once digit selection has begun (the first #, *. or 0) the first non-special character terminates the numeric part of the format. If the last digit designator was #, * or 0, all further characters in the format are floated right and leading spaces, asterisks or zeros are used to make up the required width.
Default numeric formats¶
If a format template is not specified for a numeric field, a default is applied. The defaults are as follows:
Type and Size |
Default Format |
---|---|
i1 |
###0 |
i2 |
#####0 |
i3 |
#######0 |
i4, i8 |
##########0 |
n4.0 |
#########0 |
n4.1 |
########0.0 |
n4.2 |
#######0.00 |
n4.3 |
######0.000 |
n4.4 |
#####0.0000 |
n8.0 |
#############0 |
n8.1 |
############0.0 |
n8.2 |
###########0.00 |
n8.3 |
##########0.000 |
n8.4 |
#########0.0000 |
r4 |
#####0.00 |
r8 |
###########0.00 |
u1 |
##0 |
u2 |
####0 |
u3 |
######0 |
u4, u8 |
#########0 |
Displaying zeroes¶
The number zero is not displayed by default. That is, when a numeric field whose value is zero is displayed or printed, nothing appears. In order to display the value zero, use a field format which forces it, as shown below:
##,###.## |
Zero will not display |
####0.00 |
Zero will display as 0.00 |
Numeric formats and alphanumeric fields¶
Numeric formats may be assigned to alphanumeric fields, which may optionally be assigned the flag n to indicate that whenever a numeric value is to assigned to the field, it should use the field format if present; otherwise a suitable default format for the value. So, when the number 2 is assigned to the following fields:
Output |
|
!temp alphafield,,a10,“#########0”,n |
[ 2] |
!temp alphafield,,a10,“######0.00”,n |
[ 2.00] |
!temp alphafield,,a10 |
[2 ] |
RELATED TOPICS |