StrToFloat Function | ![X#](../icons/logo100.jpg) |
Convert a string containing a numeric value to a numeric data type.
Namespace:
XSharp.RT
Assembly:
XSharp.RT (in XSharp.RT.dll) Version: 2.19
Syntax FUNCTION StrToFloat(
c AS STRING
) AS FLOAT
public static Float StrToFloat(
string c
)
Request Example
View SourceParameters
- c
- Type: String
Return Value
Type:
FloatThe numeric value as a FLOAT.
Remarks
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.
Examples
This example compares the results when SetFixed() is TRUE and when it is FALSE:
1FUNCTION Start()
2 SetDecimal(3)
3 SetFixed(FALSE)
4 ? Val("12.1234")
5 SetFixed(TRUE)
6 ? Val("12.1234")
7 RETURN TRUE
These examples illustrates Val() with SetFixed() set to TRUE and SetDecimal() set to 2:
1SetDecimal(2)
2SetFixed(TRUE)
3? Val("12.1234")
4? Val("12.1256")
5? Val("12A12")
6? Val("A1212")
7? Val(Space(1))
8? Val(" 12.12")
9? Val("12 .12")
This example applies Val() on a hexadecimal string:
See Also