CODESYS TRUNC

TRUNC is an IEC operator in the CODESYS Development System that converts a REAL value into the DINT data type. It keeps only the integer part of the number, discarding the fractional part. For example, TRUNC(1.9) gives 1 and TRUNC(-1.4) gives -1.

Source checked2/2 values · 2026-10-26

Specification

2 sources
Languageiec 61131 3
CodeTRUNC
DialectCODESYS

Study notes

  • TRUNC converts the REAL data type into the DINT data type and takes only the integer part of the number.
  • In CODESYS V2.3 the TRUNC operator converts REAL into INT; importing a V2.3 project automatically replaces TRUNC with TRUNC_INT.
  • If DINT or INT cannot represent the input value, the result of the function is undefined and the behaviour is platform-dependent.
  • Example in ST: diVar := TRUNC(1.9); (* Result: 1 *).
  • Example in ST: diVar := TRUNC(-1.4); (* Result: -1 *).
↑↓ navigate↵ openesc close