Convert a string containing a numeric value to a numeric data type.
XSharp.RT (in XSharp.RT.dll) Version: 2.16
Syntax Request Example
c AS STRING
) AS FLOAT
public static Float StrToFloat(
- Type: String
The numeric value as a FLOAT.
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: