Type Conversion Functions

Overview

It is not allowed to convert implicitly from a larger type to a smaller type (for example, from INT to BYTE or from DINT to WORD). To achieve this, you have to perform special type conversions. You can basically convert from any elementary type to any other elementary type.

Syntax

Typed conversion: <elem.type1>_TO_<elem.type2>

Overloaded conversion: TO_<elem.type2>

If the operand value for a type conversion operator is outside the value range of the target data type, the result output depends on the controller 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.

NOTICE
UNDEFINED OUTPUT
Verify that the values of the target data type are within the expected range after type conversion.
Failure to follow these instructions can result in equipment damage.

When converting the data type to STRING or WSTRING, the typed value is left-aligned as a character string and truncated if it exceeds the length of the target string variable.

NOTICE
STRING MANIPULATION
Declare a return variable of sufficient size for the type conversion operators <>_TO_STRING and <>_TO_WSTRING.
Failure to follow these instructions can result in equipment damage.

The following type conversions are supported: