TRUNC_INT

The IEC operator is used for conversion from data type REAL to data type INT. TwinCAT only uses the amount of the integer part of the number.

TRUNC_INT 1:

TRUNC_INT corresponds to the operator TRUNC in TwinCAT 2.x PLC and automatically used instead of it when TwinCAT 2.x PLC projects are imported. Note the changed function of TRUNC.

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

TRUNC_INT 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_INT(1.9);  (* Result: 1 *) 
nVar2 := TRUNC_INT(-1.4); (* Result: -1 *)

See also: