Val Function

Action

Converts a string to a number.

Syntax

nNum = Val(sToConvert)
Variable Description
nNum The returned number. NUMBER.
sToConvert The string to convert. STRING.

Notes

Val is the inverse of Str; it converts a string to a numeric value. Val evaluates sToConvert until it encounters a non-numeric character, the end of the string, or a second period (.) character. It interprets the first period character it encounters, if any, as a decimal point.

Val converts a string that contains a period to a REAL. A string without a period is converted to an INTEGER.

Val accepts values up to the maximum allowed for the converted type. For strings that are converted to an integer the maximum allowed value is 2147483647. Otherwise, you will receive an error message regarding an overflow or underflow, meaning that the number you define is within the minimum or maximum Silk Test Classic can represent.

Example

Print(Val("1234")) // prints: 1234
Print(Val("-.00432")) // prints: -0.004320
Print (Val ("x")) // prints: 0