strToFloat (Function)

Top  Previous  Next

Architecture:

X32 / NX32 / NX32L

Device support:

ALL

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.

 

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 := strToFloat( str := "1234.56789");
b := strToFloat( str := "-1.23456789e+3");
DebugMsg( message := "a + b = " + floatToStr(v:= a + b));
 
END_PROGRAM;