IB Statements/num

From CometWiki

Jump to: navigation, search

NUM function

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:

If both leading a trailing signs are present in the string-argument, the trailing sign determines the sign of the result. The sign cannot be imbedded within the string-argument. If the sign is omitted, the value is considered to be positive.

Only one decimal point is allowed in the string-argument. If no decimal point is present, it is assumed to follow the right-most digit.

A blank space cannot appear within the string-argument value, but may separate the value from the sign(s).

Dollar signs ($) are not permitted in the string-argument. The numeric-error-argument is a numeric variable or numeric array element with a length and precision of at least 1.0 If the NUM function successfully converts the string-argument, the numeric-error-argument is set to 0. If the conversion is unsuccessful, it is set to 1.

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).

Personal tools