You can explicitly call type conversion operators. The type conversion operators described
below are available for typed conversions from one elementary type to another elementary
type, as well as for overloading. Conversions from a "larger" type to a "smaller"
type are also implicitly possible (for example, from INT
to BYTE
or from DINT
to WORD
).
Typed conversion: <elementary data type> _TO_ another elementary data type>
Overloaded conversion: TO_ <elementary data type>
Elementary Data Types
<elementary data type> = __UXINT | __XINT | __XWORD | BIT | BOOL | BYTE | DATE | DATE_AND_TIME | DINT | DT | DWORD | INT | LDATE | LDATE_AND_TIME | LDT | LINT | LREAL | LTIME | LTOD | LWORD | REAL | SINT | TIME | TOD | UDINT | UINT | ULINT | USINT | WORD
The keywords T
, TIME_OF_DAY
and DATE_AND_TIME
are alternative forms for the data types TIME
, TOD
, and DT
. T
, TIME_OF_DAY
and DATE_AND_TIME
are not represented as a type conversion command.




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

String manipulation when converting to STRING
or WSTRING
When converting the type to STRING
or WSTRING
, the typed value is left-aligned as a string and truncated if it is too long. Therefore,
declare the return variable for the type conversion operators <>_TO_STRING
and <>_TO_WSTRING
long enough that the string has enough space without any manipulation.