COBOL Manual for TNS and TNS/R Programs

Intrinsic Functions
HP COBOL Manual for TNS and TNS/R Programs522555-006
14-39
NUMVAL Function
The returned value is the numeric value represented by string. The format of the
value depends on the size of string. If the length of string is fewer than 10
characters, the equivalent PICTURE is S9(n)V9(n-1), where n is the number of
characters. Any size greater than 9 characters results in an equivalent PICTURE of
S9(19)V9(18). This is a special internal item that cannot be expressed by the user.
Using it is inefficient, so it is best to avoid using a string that is longer than 9
characters.
If the NUMVAL function is moved to an alphanumeric item, the results might not be
what is expected because of the implied PICTURE described previously. For string
sizes greater than 10, the result is changed to S9(18).
Example 14-27. NUMVAL Function
Code:
DATA DIVISION
WORKING-STORAGE SECTION.
01 A PICTURE S99V99.
PROCEDURE DIVISION.
MOVE FUNCTION NUMVAL ("35") TO A.
DISPLAY A.
MOVE FUNCTION NUMVAL ("35.") TO A.
DISPLAY A.
MOVE FUNCTION NUMVAL ("35.75") TO A.
DISPLAY A.
MOVE FUNCTION NUMVAL (".35") TO A.
DISPLAY A.
MOVE FUNCTION NUMVAL (" - 35.75 ") TO A.
DISPLAY A.
MOVE FUNCTION NUMVAL (" 35.75 CR") TO A.
DISPLAY A.
Output:
35.00
35.00
35.75
00.35
-35.75
-35.75