Returns the numerical value of a string sStr based on the predefined radix lBase.
[ d = ] Val ( sStr [, lBase ] )
The Val procedure syntax has the following parts:
Name |
Type |
Description |
d |
Double |
The converted number |
sStr |
Val BString |
String to convert |
lBase |
Val Long |
Radix to use in conversion (2-36 or 0). The default value is 0. |
Val may be used to convert strings to numbers in various radixes.
If lBase is 10, the string can have the following format:
[whitespace] [sign] [digits] [.digits] [ e | E][sign]digits]
Where whitespace consists of a space or tab character.
The first character that does not fit this format stops the conversion.
If lBase is not 10, the string can have the format:
[whitespace] [+ | -] [0 [ x | X ]] [digits]
If lBase is between 2 and 36, then it is used as the base of the number.
If lBase is 0, the initial characters of the string are used to determine the base.
If the first character is '0' and the second character is 'x' or 'X', then the string is interpreted as a hexadecimal integer.
If the first character is '0' and the second character is 'b' or 'B', then the string is interpreted as a binary (base 2) integer.
If the first character is 0 and the second character is not 'x', 'X', 'b' or 'B', then the string is interpreted as an octal integer; otherwise, it is interpreted as a decimal number.
If the first character is '1' through '9', then the string is interpreted as a decimal integer. The letters 'a' through 'z' (or 'A' through 'Z') are assigned the values 10 through 35; only letters whose assigned values are less than base are permitted.
The function returns 0 if no conversion could be performed.
d = Val("123.456ABc",10) ! now d = 123.456
d = Val("FF", 16) ! now d = 255
d = Val("0xFF") ! now d = 255
d = Val("0b101") ! now d = 5
d = Val("010", 0) ! now d = 8
d = Val("77", 8) ! now d = 63
d = Val("101", 2) ! now d = 5
dl= Val("-9223372036854775808") ! now dl(DLong)=-9223372036854775808