Introduction | Language Structure | IB Statements | File System | Comet 32 Runtime | Index |
| Syntax: | NUM(string-argument, numeric-error-argument) |
| Discussion: |
The NUM function converts a string-argument into its equivalent
numeric value, only if the contents of the string-argument are
numeric characters.
The string-argument may be a string constant, a single-element string variable, a string array element, a string expression, or a string function. The string-argument can contain only numeric digits (0 through 9), a decimal point, a leading or trailing sign (+ or -), and blank spaces. Notes:
Note: If the conversion is unsuccessful, the NUM function itself will return a value of zero. The intermediate result of the NUM function is stored in an accumulator with a fixed precision of 16.8. Digits that are more than eight places on either side of the decimal point are truncated. If the result is stored in a receiving numeric variable, the precision is adjusted to the defined precision of that variable. |
| Example: |
VALUE = NUM(AMOUNT$,ERR)In the above example, the value contained in the string variable AMOUNT$ is converted to numeric form. This result is then stored in the numeric variable VALUE. The numeric-error-argument ERR will be 0 if the conversion is successful or 1 if it is not successful. For example, if AMOUNT$ equals "5542.234-" (a string), then VALUE will equal 5542.234- (a number), and ERR will equal 0 (indicating a successful conversion). Or, if AMOUNT$ equals "555-1212" (a string), then VALUE will equal 0 and ERR will equal 1 (indicating an unsuccessful conversion due to the imbedded dash in the string-argument). |