strToDouble (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 DOUBLE.

 

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: DOUBLE

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

 

Declaration:

FUNCTION strToDouble : DOUBLE;
VAR_INPUT
str : STRING;
END_VAR;

 

 

Example:

INCLUDE rtcu.inc
INCLUDE math.inc
 
PROGRAM test;
VAR
  a : DOUBLE;
  b : DOUBLE;
END_VAR;
 
a := strToDouble( str := "1234.56789");
b := strToDouble( str := "-1.23456789e+3");
DebugMsg( message := "a + b = " + doubleToStr(v:= a + b));
 
END_PROGRAM;