Convert a string containing a numeric value to a numeric data type.
XSharp.RT (in XSharp.RT.dll) Version: 2.5
cNumber AS STRING
) AS USUAL
public static Usual Val(
- Type: String
The string to convert. <cNumber> can be in any of the compiler-supported base formats, such as binary, decimal, hex, or scientific. When in scientific format, a decimal point is necessary to identify the base "E". So Val("1E+1") equals 1 but Val("1.0E+1") equals 10.0. Moreover, "+INF" and "-INF" (both must be in uppercase) represent +infinity and -infinity.
<cNumber> as a numeric value.
If <cNumber> is a valid numeric expression, Val() processes it all. However, if <cNumber> is not entirely a valid numeric expression but does contain decimal numerics, Val() evaluates it until it reaches a second decimal point, the first non-numeric character, or the end of the expression.
Leading spaces are always ignored.
All variables containing a FLOAT type have internal picture information (like a template) relating to digits and decimals (see FloatFormat()).
For data base fields of type FLOAT, such picture information resides in the database header structure and is obtainable by FieldVal().
With the Val() function and with literal floats (that is, hard-coded in source code and thus known at compile-time), the number of decimals is derived from the hard-coded decimal portion and the number of digits is taken from the SetDigit() or SET DIGIT setting.
Str() and Transform() are closely related to Val() since each converts numeric values to strings.
This example compares the results when SetFixed() is TRUE and when it is FALSE:
4 ? Val("12.1234")
6 ? Val("12.1234")
7 RETURN TRUE
These examples illustrates Val() with SetFixed() set to TRUE and SetDecimal() set to 2:
8? Val(" 12.12")
9? Val("12 .12")
This example applies Val() on a hexadecimal string: