FutureBasic Logo

<<    Index    >> FutureBasic 5

val   function

numericValue = val( PascalString )

If PascalString contains the characters of a number in any of the standard FutureBasic formats (decimal, hex, octal or binary), val returns the number's value.
val ignores leading spaces in PascalString. When it finds a non-space character, it evaluates the remaining characters in PascalString until it encounters a character which is not part of the number. Thus, for example, the string "3245.6" would be evaluated as 3245.6, but the string "32W45.6" would be evaluated as 32. If the first non-space character in PascalString can't be recognized as part of a number, val returns zero. val performs the opposite of functions such as str$, hex$, oct$, bin$ and uns$.

data "-3.2", "1.4E2", "&4C1", "9+7"
for i = 1 to 4
   read s$
   print s$, val(s$)

program output:
-3.2 -3.2
&4C1 1271
9+7 9

If PascalString represents an integer, consider using the val& function, which is faster.

See Also:
val&; mki$; cvi; str$; hex$; oct$; bin$; uns$; Appendix C - Data Types and Data Representation