Skip to main content

Operators for type conversion

Important

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.

Important

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.

String manipulation

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.

Type conversion

You can call type conversion operators explicitly.

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).