NUM(), NUMS()

Top  Previous  Next

 

The NUM() function tests whether a string can be converted to a number. The NUMS() function is similar to NUM() but operates on successive elements of a dynamic array, returning a similarly structured dynamic array of results.

 

 

Format

 

NUM(string)

 

where

 

stringevaluates to the string to be tested.

 

 

The NUM() function returns True if the string can be converted to a number. The function returns False for a string which cannot be converted to a number. The following string values would all return True:

18

-6

3.9

-77.6

 

Note that a null string is a valid representation of zero and hence also causes NUM() to return True.

 

 

Leading and trailing spaces are ignored but a string that is just one or more spaces is not numeric.

 

If the NUMERIC.EXPONENT mode of the OPTION command is enabled, The NUM() function will accept exponent style values such as 123.45E-1 as being numeric.

 

 

 

Example

 

LOOP

  DISPLAY "Enter part number ":

  INPUT PART.NO

UNTIL PART.NO # "" AND NUM(PART.NO)

  PRINTERR "Part number is invalid"

REPEAT

 

This program fragment prompts for and inputs a part number. If the data entered is null or cannot be converted to a number, an error message is displayed and the prompt is repeated.