# CODESYS TRUNC

Instructions · `TRUNC` · verification: source checked

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.

## Specification

| Property | Value |
|---|---|
| Language | iec 61131 3 |
| Code | TRUNC |
| Dialect | CODESYS |

## 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 *).

## Sources

1. [Beckhoff Information System](https://infosys.beckhoff.com/content/1033/tc3_plc_intro/2529079691.html) (accessed 2026-10-26)
2. [CODESYS Group](https://content.helpme-codesys.com/en/CODESYS%20Development%20System/_cds_operator_trunc.html) (accessed 2026-10-26)

---

Source page: https://machineschema.com/instruction/iec-trunc  
JSON: https://machineschema.com/instruction/iec-trunc.json  
License: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Cite Machine Schema and the original sources.
