Operator ‘TRUNC’ΒΆ

The IEC operator is used for converting the REAL data type into the DINT data type. CODESYS takes only the integer part of the number.

Note

In CoDeSys V2.3, the TRUNC operator converts REAL into INT. If you import a V2.3 project, then CODESYS automatically replaces TRUNC with TRUNC_INT.

If CODESYS cannot represent the input value by a DINT or INT, then the result of this function is undefined. The behavior of such input values is platform-dependent.

Hint

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.

Examples

Result in diVar: 1

ST

diVar := TRUNC(1.9); (* Result: 1 *)

diVar := TRUNC(-1.4); (* Result: -1 *)

See also