TRUNC

TRUNC 1:

Undefined result if the value range is exceeded

If the input value of a type conversion operator is outside the value range of the output data type, the result of the operation is not defined and depends on the platform. This is the case, for example, when a negative operand value is converted from LREAL to the target data type UINT. An exception error is also possible!

TRUNC 2:

Loss of information possible

If a larger data type is converted to a smaller data type, information may be lost.

This IEC operator converts from the data type REAL to the data type DINT. TwinCAT only uses the integer part of the number.

TRUNC 3:

In TwinCAT 2.x PLC Control, the TRUNC operator converts from REAL to INT. If you import a TwinCAT 2.x PLC project, TwinCAT automatically replaces TRUNC with TRUNC_INT.

Examples:

ST code

Result

TRUNC(1.9)

1

TRUNC(-1.4)

-1