Futurebasic/Language/Reference/val

From Wikibooks, open books for an open world
Jump to navigation Jump to search

VAL[edit | edit source]

Syntax[edit | edit source]

numericValue = VAL(string$)

Description[edit | edit source]

If string$ contains the characters of a number in any of the standard FB formats (decimal, hex, octal or binary), VAL returns the number's value.

VAL ignores leading spaces in string$. When it finds a non-space character, it evaluates the remaining characters in string$ 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 string$ 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$.

Example[edit | edit source]

DATA "-3.2", "1.4E2", "&4C1", "9+7"
FOR i = 1 TO 4
   READ s$
   PRINT s$, VAL(s$)
NEXT

program output:
<code>-3.2 -3.2
1.4E2140
&4C1 1271
9+7 9

Notes[edit | edit source]

If string$ represents an integer, consider using the VAL& function, which is faster.

See Also[edit | edit source]

VAL&amp; MKI$; CVI; STR$; HEX$; BIN$; OCT$; UNS$; <Image was here> Appendix C: Data Types and Data Representation