strfloat()
Description
Convert from text (string) to floating point.
Syntax
strfloat(string[]);
Parameters
Variable | Input |
|---|---|
| A string containing a floating point number in characters. This may be either a packed or unpacked string. The string may specify a fractional part, for example “123.45”. |
Returns
The value in the string, or zero if the string did not start with a valid number.
Function call example
Example of converting string to float
new data1[7] = ''125.89'';
new Float: strToFl;
main(){
strToFl = strfloat(data1);
while(1){
Delay(100);
}
}Notes and Warnings
Use unpacked string by writing two times single comma (''example'') instead of writing single double comma ("example").
When using unpacked string always leave one more array element:
new data1[7] = ''125.89'';
Here we see that to store whole string we'd need only 6 array elements (since 125.89 is 6 elements), but we have to add one extra array element to store final zero, that's why data1 array size is 7 instead of 6.