When numeric attributes are defined in a data model or a work set, the size and decimal digits are defined using a syntax such as (w,d). W represents the width of the variable in total digits, and d is the number of digits assumed to be on the right of a decimal point. An integer, containing 5 digits, would be defined as a (5,0) variable. A real value, containing 12 digits total, with 5 decimal digits (and therefore 8 integer digits) would be defined as a (12,5) variable.
A floating decimal point is provided using a sliding pattern matching algorithm to match a literal character specified in the edit pattern at the specified decimal point position. If no literal character is present in the edit pattern picture string at the specified decimal position, then the right-most infix literal is assumed to be the decimal point and the input is aligned on that literal. If the data cannot be aligned to the implied decimal point, then it is assumed to be an integer, and a decimal point is forced to the right of the last significant digit.
The following table illustrates several alignment examples.
|
Case |
Edit Pattern |
Input |
Aligned Input |
Variable (w,d) |
Value |
|---|---|---|---|---|---|
|
1 |
ZZZ,ZZ9.99 |
123.1 |
000,123.10 |
(8,2) |
00012310 |
|
2 |
ZZZ,ZZ9.99 |
1,234 |
001,234.00 |
(8,2) |
00123400 |
|
3 |
ZZZ,ZZ9.99 |
1.0000 |
000,001.00 |
(8,2) |
00000100 |
|
4 |
ZZ9.999999 |
1.20000 |
001.20 |
(5,2) |
00120 |
|
5 |
ZZ9,99 |
1,2 |
001,20 |
(5,2) |
00120 |
|
6 |
ZZ9,99 |
12 |
012,00 |
(5,2) |
01200 |
|
7 |
ZZ9$99 |
1$2 |
001$20 |
(5,2) |
00120 |
When the edit pattern is defined, only digit specifiers are recognized. All other characters are literal. They are placed in the edit picture just as the user entered them. The literals are not processed by the runtime, except for formatting. A period in the edit picture is not assumed to be the decimal point.
The runtime locates the decimal point position within the edit pattern, and aligns it with the implied decimal point of the variable.
The value column does not have a decimal point because the actual internally-stored value has an implied decimal point based on the defined width and decimal digits. The input is aligned on the implied decimal point and the right-most infix literal. Then, zeroes are added or removed so the digit string conforms to the edit pattern.
Once aligned to the implied decimal point, the value is converted and stored in the internal variable. Alignment may discard insignificant digits, as in case 4 in the Input Decimal Point Alignment table. However, if any significant digits are to be discarded, then the field is flagged as an error and the user is allowed to correct the input (either underflow or overflow).
Case 1 in the Input Decimal Point Alignment table shows the input string “123.1” of the user is aligned over the edit pattern of “ZZZ,ZZ9.99”, based on the right-most infix literal rule and the defined width and decimal place of the variable. The missing digits are then supplied as zeroes, resulting in an aligned input of “123.10”. This is then converted to the internal representation and stored in the variable.
To obtain a fixed decimal point, associate the edit pattern picture with an integer variable and implement logic for the appropriate scaling.
|
Copyright © 2013 CA.
All rights reserved.
|
|