{"id":"iec-trunc","model_id":"TRUNC","name":"CODESYS TRUNC","summary":"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.","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 *)."],"safety_notes":[],"sources":[{"url":"https://infosys.beckhoff.com/content/1033/tc3_plc_intro/2529079691.html","title":"Beckhoff Information System","accessed":"2026-10-26"},{"url":"https://content.helpme-codesys.com/en/CODESYS%20Development%20System/_cds_operator_trunc.html","title":"CODESYS Group","accessed":"2026-10-26"}],"verification":{"status":"source_checked","checked_at":"2026-10-26","values":2,"method":"llm_source_check"},"updated_at":"2026-10-26","type":"instruction","spec":{"language":"iec_61131_3","code":"TRUNC","parameters":[],"dialect":"CODESYS","related":[],"standards":[]},"url":"https://machineschema.com/instruction/iec-trunc","license":"https://creativecommons.org/licenses/by/4.0/"}