The NUM function may be used to test a given expression for numeric data.
Format
NUM(expr) |
Parameter(s)
expr |
Expression to be tested. |
Description
The NUM function determines whether the expr is a numeric or a non-numeric string. If expr contains only numeric characters, the function evaluates to true and a value of 1 is returned. If expr contains non-numeric characters, the expression evaluates to false and a value of 0 is returned.
A single decimal point (.) within a numeric string is considered a numeric character; that is, if the expression contains only numbers and a decimal point, the expression evaluates to true (1).
However, if a second decimal point is encountered in the string, the expression evaluates to false (0) since a second decimal point is meaningless in a mathematical expression.
Commas and dollar signs are never considered numeric characters; that is, a numeric string containing a comma (,) or dollar sign ($) evaluates to false, regardless of whether all other characters are numbers.
Example
In this application, the NUM function is used to verify that a valid numeric response was input:
PRINT "ENTER YOUR ACCOUNT NUMBER: " : INPUT ACCT,6,"?"_ IF NOT(NUM(ACCT)) THEN STOP |
Note that the decimal precision used by the program is a consideration in this example. For example, if the precision is 4 (the default) and the user enters a value with 5 decimal positions (such as 3.14159), the NUM function returns false (0) and the program stops. See PRECISION Statement for more information.
See Also