Val Function
Converts a character string that consists of numbers into their numerical value and returns that value.
Syntax
Val(string)
Parameters
- string
- Specify a string expression which contains only numeric characters. The string may also contain a prefix:
&H (hexadecimal), &O (octal), or &B (binary).
Return Values
Returns an integer or floating point result depending upon the input string. If the input string has a decimal point character than the number is converted into a floating point number. Otherwise the return value is an integer.
Description
Val converts a character string of numbers into a numeric value. The result may be an integer or floating point number. If the string passed to the Val instruction contains a decimal point then the return value will be a floating point number. Otherwise it will be an integer.
See Also
Abs, Asc, Chr$, Int, Left$, Len, Mid$, Mod, Right$, Sgn, Space$, Str$
Val Function Example
The example shown below shows a program which coverts several different strings to numbers and then prints them to the screen.
Function ValDemo
String realstr$, intstr$
Real realsqr, realvar
Integer intsqr, intvar
realstr$ = "2.5"
realvar = Val(realstr$)
realsqr = realvar * realvar
Print "The value of ", realstr$, " squared is: ", realsqr
intstr$ = "25"
intvar = Val(intstr$)
intsqr = intvar * intvar
Print "The value of ", intstr$, " squared is: ", intsqr
Fend
Here's another example from Command window.
> Print Val("25.999")
25.999
>
← V VSD Statement →