strToFloat (Function)

Top  Previous  Next

Architecture:

X32 / NX32 / NX32L

Firmware version:

3.10 / 1.00.00


This function converts a string to a FLOAT.

 

Note: This function works with DOUBLE, but can also work with FLOAT as described in the Floating-point math introductory section.

 

Please note that when using the Floating-Point Math functions in X32 and NX32 compilation mode then math.inc must be explicitly included by the application.

When using the NX32L compilation mode, math.inc is included by default.

 

Input:

str : STRING

String to convert.

 

Returns: FLOAT

The value of the string. If the string can not be parsed, 0 is returned.

 

Declaration:

FUNCTION strToFloat : FLOAT;
VAR_INPUT
   str : STRING;
END_VAR;

 

 

Example:

INCLUDE rtcu.inc
INCLUDE math.inc
 
PROGRAM test;
VAR
   a : FLOAT;
   b : FLOAT;
END_VAR;
 
a := strToFloatstr := "1234.56789");
b := strToFloatstr := "-1.23456789e+3");
DebugMsgmessage := "a + b = " + floatToStr(v:= b));
 
END_PROGRAM;