The NUMVAL-C function returns the numeric value represented by the character string specified by argument-1. Any optional currency sign specified by argument-2 and any optional commas preceding the decimal point are ignored.
The type of this function is numeric.
Format
FUNCTION
NUMVAL-C
(argument-1 [argument-2])
Arguments
argument-1 must be from the category alphanumeric or national and must have one of the following two formats:
['BLANK'] [+ | -] ['BLANK'] [wz] ['BLANK'] {digit[,digit]...[.[digit]] | .digit} ['BLANK']
or
['BLANK'] [wz]['BLANK'] {digit[,digit]...[.[digit]] | .digit} ['BLANK']
[+ | - | CR | DB ]['BLANK']
'BLANK'
String of one or more spaces
wz
Currency symbol: string of one or more characters (argument-2)
digit
One or more digits of the set {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
The letter string "CR" or "DB" in upper case must be specified for CR and DB.
If the DECIMAL-POINT IS COMMA clause is specified in the SPECIAL-NAMES paragraph, the functions of the comma and decimal point in argument-1 are reversed.
The total number of digits in argument-1 must not exceed 31.
argument-2, if specified, must be of the same class as argument-1.
If argument-2 is not specified, the character used for cs is the currency symbol specified for the program.
Returned values
The returned value is the numeric value represented by argument-1.
- If argument-1 has a variable length or a length with more than 16 characters (or more than 14 characters if the error return value is required), the result can deviate from the exact value, since a floating point representation is required for the return value.
- If argument-1 has a fixed length of up to 14 characters then the error default value is -999’999’999’999’999’999.
If argument-1 has a variable length or a length of more than 14 characters then the error default value is -9’999’999’999’999’999’999’999’999’999’999.
See also: NUMVAL
Example 9-32
... DATA DIVISION. WORKING-STORAGE SECTION. 01 V PIC X(8) VALUE "- $15.00". 01 R PIC 99V99. 01 RES PIC 99.99. PROCEDURE DIVISION. P1 SECTION. MAIN. COMPUTE RES = FUNCTION NUMVAL-C (V). DISPLAY RES UPON T. STOP RUN.
Result: 15.00