



NOTICE

If the operand value for a type conversion operator is outside of the value range
of the target data type, then the result output depends on the processor type and
is therefore undefined. This is the case, for example, when a negative operand value
is converted from LREAL
to the target data type UINT
.
Information can be lost when converting from larger data types to smaller data types.




NOTICE

The rounding logic for borderline cases depends on the target system or the FPU (Floating
Point Unit) of the target system. For example, a value of -1.5
can be converted differently on different controllers.
Catch value ranges overflows across the application to program code-independent from the target system.
The IEC61131-3 specification does not provide for overloaded functions.
If you want to program strictly according to IEC61131-3, then you should use the operators
of the syntax <type> _TO_ <another type>
as described in the following sections.
The rules for typed conversions also apply here for overloading.
The operators convert values into other data types, explicitly specifying only a target data type and no initial data type (data type of the operands) ("overloaded conversion"). Overloading is not part of the IEC 61131-3 specification.
Call syntax
<variable name> := <TO operator> ( <operand> ); <operand> = <variable name> | <literal>
Operators
TO___UXINT TO___XINT TO___XWORD TO_BIT TO_BYTE TO_BOOL TO_DATE TO_DINT TO_DT TO_DWORD TO_INT TO_LDATE TO_LDT TO_LINT TO_LREAL TO_LTIME TO_LTOD TO_LWORD TO_REAL TO_SINT TO_STRING TO_TIME TO_TOD TO_UDINT TO_UINT TO_ULINT TO_USINT TO_WORD TO_WSTRING
Examples
ST implementation language:
VAR iNumber_1 : INT; rNumber_2 : REAL := 123.456; iNumber_2 : INT; xIsTrue : BOOL; sOutputText : STRING; sText : STRING := 'Hello World!'; wsText: WSTRING; dateEvent : DATE := D#2019-9-3; uiEvent : UINT; uxiData : __UXINT; END_VAR iNumber_1 := TO_INT(4.22); (* Result: 4 *) iNumber_2 := TO_INT(rNumber_2); (* Result: 123 *) xIsTrue := TO_BOOL(1); (* Result: TRUE *) sOutputText := TO_STRING(342); (* Result: '342' *) wsText := TO_WSTRING(sText); (* Result: "Hello World!" *) uiEvent := TO_UINT(dateEvent); (* Result: 44288 *) uxiData := TO___UXINT(iNumber_2); (* Result: 123 *)