NUMVAL-C

The NUMVAL-C function returns the numeric value represented by the alphanumeric character string or national character string specified as argument-1. The function removes the currency string, if any, and any grouping separators (commas or periods) to produce a numeric value.

The function type is numeric.

Format

Read syntax diagramSkip visual syntax diagramFUNCTION NUMVAL-C(argument-1 argument-2)

argument-1
Must be an alphanumeric literal, a national literal, or a data item of class alphanumeric or class national that contains a character string in either of the following formats:

Format 1: argument-1

Read syntax diagramSkip visual syntax diagramspace +  - spacecsspacedigit,digit.digit.digitspace

Format 2: argument-1, monetary format

Read syntax diagramSkip visual syntax diagramspacecsspacedigit,digit.digit.digitspace +  - CRDBspace
space
A string of one or more spaces.
cs
The string of one or more characters that form the currency sign. At most one copy of the characters specified by cs can occur in argument-1.
digit
A string of one or more digits. If the ARITH(COMPAT) compiler option is in effect, the total number of digits must not exceed 18. If the ARITH(EXTEND) compiler option is in effect, the total number of digits must not exceed 31.

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.

argument-2
Specifies the currency string value.

The following rules apply:

  • argument-2 must be specified if the program contains more than one CURRENCY SIGN clause.
  • argument-2, if specified, must be of the same class as argument-1.
  • argument-2 must not contain any of the digits 0 through 9, any leading or trailing spaces, or any of the special characters '+', '-', '.', or ','.
  • argument-2 can be of any length valid for an elementary or group data item of the class of argument-2, including zero.
  • Matching of argument-2 is case sensitive. For example, if you specify argument-2 as 'CHF', it will not match 'ChF', 'chf' or 'chF'.

If argument-2 is not specified, the character used for cs is the currency symbol specified for the program.

The returned value is a floating-point approximation of the numeric value represented by argument-1. The precision of the returned value depends on the setting of the ARITH compiler option. For details, see Converting to numbers (NUMVAL, NUMVAL-C) in the Enterprise COBOL Programming Guide.