Revision [11688]

This is an old revision of KeyPgVal made by JeffMarshall on 2007-11-10 11:05:35.

 

VAL


Converts a string to a floating point number

Syntax:
Usage:
result = Val( strnum )

Parameters:
strnum
the string containing a number to convert

Return Value:
Returns a converted KeyPgDouble Double precision number.
If the first character of the string is invalid, Val will return a 0.

Description:
Val("10") will return 10.0, and Val("10.10") will return 10.1. The function parses the string from the left, skipping any white space, and returns the longest number it can read, stopping at the first non-suitable character it finds. Scientific notation is recognized, with "D" or "E" used to specify the exponent.
Val can be used to convert integer numbers in binary / octal / hexadecimal format, if they have the relevant identifier ("&B" / "&O" / "&H") prefixed, for example: Val("&HFF") returns 255.
Note:
If you want to return an integer, consider using KeyPgValint ValInt or KeyPgVallng ValLng instead. They are faster, since they don't use floating-point numbers, and only KeyPgVallng ValLng provides full 64-bit precision for KeyPgLongint LongInt types.

If you want to convert a number into string format, use the KeyPgStr Str function.

Examples:
Dim a As String, b As Integer
a = "20xa211"
b = Val(a)
Print a, b


20xa211   20


Differences from QB:
See also:
Back to Converting Data Types
Back to String Functions
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki



sf.net phatcode