User`s manual

5-11
VAL
(string)
Performs the inverse of the STR$ function: returns the number represented
by the characters in a string argument. The numerical type of the result can
be integer, single precision, or double precision, as determined by the rules
for the typing of constants (see page 4/18). For example, if A$="12" and
B$="34" then
VAL(A$+ "."+B$)
returns the value 12.34.
VAL(A$+"E"+B$)
returns the value 12E34, that is 12 x 10
34
.
VAL operates a little differently on mixed strings - strings whose values
consist of a number followed by alphanumeric characters. In such cases, only
the leading number is used in determining VAL; the alphanumeric remainder
is ignored.
For example: VAL("100 DOLLARS") returns 100.
This can be a handy short-cut in examining addresses, for example.
Example Program
10 REM "WHAT SIDE OF THE STREET?"
15 REM EVEN=NORTH. ODD=SOUTH
20 INPUT "ADDRESS: NUMBER AND STREET"; AD$
30 C=INT(VAL(AD$)/2)*2
40 IF C=VAL(AD$) PRINT "NORTH SIDE": GOTO 20
50 PRINT "SOUTH SIDE": GOTO 20
RUN the program, entering street addresses like "1015 SEVENTH AVE".
If the string is non-numeric or null, VAL returns a zero.