11. Report-Writer Expressions and Formats : Format Specifications : Numeric Templates
 
Share this page                  
Numeric Templates
If you need more complex numeric formats than the standard formats offer, you can specify a numeric format in a template form. Essentially, a template is an example of how the formatted output will appear.
Instead of specifying an actual sequence of digits, however, you use specially designated characters to indicate what must be printed at that position in the template. For instance, a Z indicates that the next digit in the number (or a space, if no digits remain) must be printed. A comma (,) in the template causes a comma to be printed in that position. So the template Z,ZZZ would cause the number 1000 to be printed as 1,000. In addition to the specially defined characters listed below, you can include any other character directly in the numeric template by preceding it with a backslash.
The general syntax of a numeric template is:
[-|*|+] '{c}'
where:
- or *
Left justifies (-), centers (*), or right justifies (+) the template. The template, like any number, is right-justified by default.
c
Is one of several special characters that can be repeated any number of times, as follows:
n or N
Prints a digit if the number contains a digit in that position. Otherwise, prints a zero. If a field is specified without n in the numeric positions and Report-Writer encounters a value of zero (0), Report-Writer enters blanks in the field.
z or Z
Prints a digit if the number contains a digit in that position. Otherwise, prints a space. This is used for standard blank-padded numeric fields.
^
(Caret) Prints a digit if the number contains a digit in that position, but rounds up the digit according to the values of the digits to the right of this position.
$
(Dollar sign) Prints a digit if the number contains a digit in that position. If no digits remain, prints a floating dollar sign immediately to the left of the last evaluated digit. Report-Writer displays a dollar sign only once in the output field. If a dollar sign has already been printed, Report-Writer prints a space in this position. This can be used to print a dollar sign directly to the left of the number, or to place a dollar sign in a fixed position in the field when used with other template characters.
-
(Minus sign—Preceding or Trailing)
For preceding: Prints a digit if the number contains a digit in that position. If no digits remain and if the number is negative, prints a floating minus sign immediately to the left of the last evaluated digit. Report-Writer prints a minus sign only once in the output field. If a minus sign has already been printed, or if the number is positive and no digits remain, Report-Writer prints a space in this position.
For trailing: Prints a minus sign in the position if the number is negative, or if the number is positive, prints a space.
+
(Plus sign—Preceding or Trailing)
For preceding: Prints a digit if the number contains a digit in that position. If no digits remain, prints a floating sign (+ or -). Report-Writer prints a plus or minus sign only once in the output field. If one has already been printed, Report-Writer prints a space in this position.
For trailing: Prints a plus sign in the position if the number is positive or a minus sign if the number is negative.
,
(Comma) Prints a comma if the number contains any digits to the left of this position. If no digits remain, prints a space.
.
(Decimal point) Prints a decimal point in this position. The template can contain only one decimal point.
*
(Asterisk) Prints a digit if the number contains a digit in this position. If no digits remain, prints an asterisk. This is useful to fill a number on the left with asterisks (for example, for checks).
space
Prints a blank space in this position. This is identical to specifying a backslash followed by a space, and is provided for convenience only. Do not use spaces as thousands separators in place of commas and a decimal point if your template contains floating characters (+ - $ [ ] ( ) < > { }). Floating characters work correctly only when used with commas and the decimal point as separators.
\c
(Backslash) Prints in the specified position any character c preceded by a backslash. This allows you to insert hyphens, slashes, or other characters into the number. (The backslash is not printed.)
CR
(Two characters) Inserts the characters "CR" (for credit) if the number is negative, or two blanks if positive. The letters "CR" appear exactly as specified, in uppercase and/or lowercase letters.
DB
(Two characters) Inserts the characters "DB" (for debit) if the number is negative, or two blanks if positive. The letters "DB" appear exactly as specified, in uppercase and/or lowercase letters.
( ) or [ ] or < >
(Parentheses, brackets or angle brackets) If the number is negative, prints it within the specified symbols.
Surround the template with single (') or double (") quotes; single quotes are recommended for consistency with requirements for quoting string constants.
Ingres evaluates the data from right to left, as it compares the number to the template.
If Report-Writer encounters a value of zero, it prints blanks (spaces) in the output field, unless the template contains n in the numeric positions. Report-Writer prints a floating symbol ($, - , or +) only once in the output field, regardless of the number of times it appears in the template.
The following examples demonstrate the use of numeric templates. The carets (^) in the Output column are used here only to show where blanks occur in the output; they do not print in your report.
Format
Value
Output
'zzzzz'
123
^^123
'zZzZz.Zz'
0
^^^^^^^^
'zzzzz.nn'
0
^^^^^.00
'zzzzz.z^'
123.438
^^123.44
'+++,+++,+++'
23456
^^^^+23,456
'---,---,---.NN'
23456.789
^^^^^23,456.79
'---,---,---.zz '
-3142.666
^^^^^-3,142.67^
'zzz,zzz,zzz.zz-'
-3142.666
^^^^^^3,142.67-
'$$$,$$$,$$$.nncr'
235122.21
^^^$235,122.21^^
'$$$,$$$,$$$.nnDb'
-235122.21
^^^$235,122.21Db
'$zz,zzz,zzn.nn'
1234.56
$^^^^^1,234.56
'$**,***,***.nn'
12345
$****12,345.00
'+$$,$$$,$$$. '
54321
^^^+$54,321.00
' nnn\-nn\-nnnn '
023243567
^023-24-3567^
-'zzzzz'
123
123^^
'(zzzzz)'
-123
(^^123)
'[[[[[z]'
-123
^^[123]