TRUNC

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

TRUNC 1:

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.

If TwinCAT cannot represent the input value with a DINT or INT number, the result of this function is undefined.

TRUNC 2:

For a type conversion operator, if the operand value is outside the value range of the target data type, the result output is undefined. This is the case, for example, when a negative operand value is converted from LREAL to the target data type UINT.

Information may be lost during type conversion from larger to smaller types.

Samples:

Result: nVar1 is 1.

ST:

nVar1 := TRUNC(1.9);  (* Result: 1 *) 
nVar2 := TRUNC(-1.4); (* Result: -1 *) 

See also: