Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
1.6.7.3 Converting to Numbers (NUMVAL, NUMVAL-C)
Ÿ Copyright IBM Corp. 1991, 1998
The NUMVAL and NUMVAL-C functions convert character strings to numbers.
Use these functions to convert alphanumeric data items that contain free
format character representation numbers to numeric form and process them
numerically. For example:
01 R Pic x(20) Value "- 1234.5678".
01 S Pic x(20) Value " $12,345.67CR".
01 Total Usage is Comp-1.
.
.
Compute Total = Function Numval(R) + Function Numval-C(S)
The difference between NUMVAL and NUMVAL-C is that NUMVAL-C is used when
the argument includes a currency symbol and/or comma, as shown in the
example. You can also place an algebraic sign in front or in the rear,
and it will be processed. The arguments must not exceed 18 digits (not
including the editing symbols). For exact syntax rules, see IBM COBOL
Language Reference.
Numeric Result: Both NUMVAL and NUMVAL-C return long (double-precision)
floating-point values. A reference to either of these functions,
therefore, represents a reference to a numeric data item. For more
information on characteristics of numeric data, see Chapter 3, "Numbers
and Arithmetic" in topic 1.3.
1.6.7.3.1 Why Use NUMVAL and NUMVAL-C
Ÿ Copyright IBM Corp. 1991, 1998
When you use NUMVAL or NUMVAL-C you don't need to statically declare
numeric data in a fixed format and input data in a precise manner. For
example, for this code:
01 X Pic S999V99 leading sign is separate.
.
.
Accept X from Console
The user of the application must enter the numbers exactly as defined by
the PICTURE clause. For example:
+001.23
-300.00
However, using the NUMVAL function, you could code:
01 A Pic x(10).
01 B Pic S999V99.
.
.
Accept A from Console
Compute B = Function Numval(A)
and the input could be:
1.23
-300