Workbench User Guide : C. Data Format Templates : Numeric Templates : Numeric Template Syntax
 
Share this page                  
Numeric Template Syntax
Numeric templates consist of one or more special characters. A special character represents some set of characters. The end user can enter any character in the set defined for a special character in the position occupied by the special character.
When you create a numeric template, use one special character for each space of the column width. For example, “$$$$” specifies that the column is four digits wide and a dollar sign should be printed to the left of whatever number is displayed in the field.
Note:  You must use quotation marks around the template characters when you specify a template in the Property Inspector. Likewise, if you are setting the FormatString attribute in your 4GL code, you must use quotation marks. For more information about the FormatString attribute, see the Language Reference Guide.
You can include any printable character directly in a template by preceding it with a backslash. For example, to include the percent symbol in a template, enter \%. The backslash does not appear in your data.
Special Template Characters
The following table describes the special template characters:
Code
Description
n
If a digit remains in the number, display the digit. If no digits remain, display zero.
z
If a digit remains in the number, display the digit. If no digits remain, display a space.
This code is used for standard blank-padded numeric fields.
$
If a digit remains in the number, display the digit. If no digits remain, display a floating dollar sign immediately to the left of the last digit. If a dollar sign has already been displayed, display a space.
This code can be used to display a dollar sign directly to the left of the number or to place a dollar sign in a fixed position in the field.
If a digit remains in the number, display the digit. If no digits are left and the number is negative, a floating minus sign is displayed immediately to the left of the last digit. If a minus sign has already been displayed, a space is inserted. If the number is positive, a space is inserted.
+
If a digit remains in the number, display the digit. If no digits are left, display a floating sign (+ or –) to the left of the last digit. If one has already been displayed, display a space.
,
If a digit remains in the number, display a comma in this position. If no digits remain, display a space.
This code is used for inserting commas to break up large numbers.
Note:  If the II_DECIMAL environment variable is set to a comma, then a comma in the template displays a period. For more information, see Environment Variables for All Platforms.
.
Display the decimal point in this spot.
Note:  If the II_DECIMAL environment variable is set to a comma, then a comma in the template displays a period. For more information, see Environment Variables for All Platforms.
*
If no digits remain, display an asterisk.
This code is useful for filling a number on the left with asterisks (for example, for checks).
^
If a digit remains in the number, display the digit, but round up the digit according to the values of the digits to the right of this position.
space
If a digit remains in the number, displays a blank space in this position.
Using this code is equivalent to specifying a backslash followed by a space.
CR
(two
characters)
If the number is negative, insert the characters CR (for credit). If the number is positive, display two blanks.
You can specify the characters in uppercase or lowercase (or one of each).
DB
(two
characters)
If the number is negative, insert the characters DB (for debit). If the number is positive, display two blanks.
You can specify the characters in uppercase or lowercase (or one of each).
\c
Any character, c, preceded by a backslash is printed in the position specified.
This code lets you insert characters such as hyphens and slashes into a template.
( ), [ ],{ },
< >
If the number is negative, displays it within the specified symbols.
Note:  The floating symbols ($, +, and –) are displayed only once in the field. If a field is specified without “n” in the numeric positions and a value of zero is encountered, the field is blanked.
Examples of Numeric Templates
The following examples demonstrate the use of templates.
Note:  A pound sign (#) indicates a blank space:
Data Type
Format
Example Data
Output
integer
zzzzzzzz
123
#####123
integer
zZzZz.Zz
0
########
integer
zzzzzzzz.nn
0
########.00
integer
+++,+++,+++
23456
####+23,456
float
---,---,---.NN
23456.789
####23,456.79
float
---,---,---.zz
3142.666
#####-3,142.67
money
$$$,$$$,$$$.nnCr
235122.21
###$235,122.21
money
$$$,$$$,$$$.nnDb
235122.21
###$235,122.21Db
money
$zz,zzz,zzn.nn
1234.56
$#####1,234.56
money
$**,***,***.nn
12345
$****12,345.00
money
+$$,$$$,$$$.nn
54321
###+54,321.00
integer
nnn\nn\nnnn
023243567
023-24-3567