Truncate (TRUNC)

This table lists the controllers and applications that support this instruction.
Architecture
Standard applications
Safety applications
CompactLogix 5370, ControlLogix 5570, Compact GuardLogix 5370, and GuardLogix 5570 controllers
Yes
No
CompactLogix 5380, CompactLogix 5480, ControlLogix 5580, Compact GuardLogix 5380, and GuardLogix 5580 controllers
Yes
Yes
When enabled, the TRUNC instruction removes (truncates) the fractional part of the Source and stores the result in the Destination.
TIP: In Logix Designer version 36, the mnemonic for this instruction changed from TRN to TRUNC.
Available Languages
Ladder Diagram
Function Block Diagram
Function Block Diagram supports these elements:
FBD Block
FBD Function
TIP:
FBD Function is applicable to CompactLogix 5380, CompactLogix 5480, ControlLogix 5580, Compact GuardLogix 5380, and GuardLogix 5580 controllers only.
Structured Text
This instruction is not available in structured text.
TIP:
Use TRUNC as an operator in an expression to compute the same result. Refer to for more information on the syntax of expressions and assignments within structured text.
Operands
IMPORTANT: Unexpected operation may occur if:
  • Output tag operands are overwritten.
  • Members of a structure operand are overwritten.
  • Except when specified, structure operands are shared by multiple instructions.
There are data conversion rules for mixing numeric data types within an instruction. See Data conversions.
Ladder Diagram
Operand
Data Type
CompactLogix
5370,
ControlLogix
5570,
Compact GuardLogix
5370, and
GuardLogix
5570 controllers
Data Type
CompactLogix 5380, CompactLogix 5480, ControlLogix 5580, Compact GuardLogix 5380, and GuardLogix 5580 controllers
Format
Description
Source
SINT
INT
DINT
REAL
REAL
LREAL
immediate
tag
Value to truncate.
Destination
SINT
INT
DINT
REAL
SINT
INT
DINT
LINT
USINT
UINT
UDINT
ULINT
REAL
LREAL
tag
Tag to store the result of the instruction.
Function Block Diagram
FBD Block
Operand
Type
Format
Description
TRUNC
FBD_TRUNCATE
tag
TRN structure
FBD Function
Input Operands (Left Pins)
Data Type
CompactLogix 5380, CompactLogix 5480, ControlLogix 5580, Compact GuardLogix 5380, and GuardLogix 5580 controllers
Description
Source
REAL
LREAL
Value to truncate
Output Operand (Right Pin)
Data Type
CompactLogix 5380, CompactLogix 5480, ControlLogix 5580, Compact GuardLogix 5380, and GuardLogix 5580 controllers
Description
Dest
LINT
Result of the function.
FBD_TRUNCATE Structure
Input Member
Data Type
Description
EnableIn
BOOL
Enable input. If false, the instruction does not execute and outputs are not updated.
Default is true.
Source
REAL
Input to the conversion instruction.
Input also takes SINT, INT, DINT, LINT, USINT, UINT, UDINT, ULINT and LREAL through input tag. But the integer type will be converted to REAL type first.
Converting SINT or INT or USINT or UINT to REAL, there is no data precision lost.
Converting 32-bit types (DINT, UDINT) to REAL, data precision could be lost. Both data types store data in 32 bits, but the REAL type uses some of its 32 bits to store the exponent value. If precision is lost, the controller takes it from the least-significant portion of the 32 bit types (DINT, UDINT).
Converting 64 bit types (LINT, ULINT and LREAL) to REAL, data precision could be lost.
Output Member
Data Type
Description
EnableOut
BOOL
Indicates if the instruction executed without fault when it was enabled.
Dest
DINT
Result of the instruction.
Description
Truncating does not round the value; rather, the non-fractional part remains the same, regardless of the value of the fractional part.
Affects Math Status Flags
Controllers
Affected Math Status Flags
CompactLogix 5380, CompactLogix 5480, ControlLogix 5580, Compact GuardLogix 5380, and GuardLogix 5580 controllers
Conditional, see .
CompactLogix
5370,
ControlLogix
5570,
Compact GuardLogix
5370, and
GuardLogix
5570 controllers
Yes
Major/Minor Faults
None specific to this instruction. Seefor array-indexing faults.
Execution
Ladder Diagram
Condition/State
Action Taken
Prescan
N/A.
Rung-condition-in is false
Set Rung-condition-out to Rung-condition-in.
Rung-condition-in is true
Set Rung-condition-out to Rung-condition-in.
Dest = Truncated value of the Source.
Postscan
N/A.
Function Block Diagram
FBD Block
Condition/State
Action Taken
Prescan
N/A
EnableIn is false
Set EnableOut to EnableIn.
EnableIn is true
Dest = Truncated value of the Source.
If overflow occurs
Clear EnableOut to false.
else
Set EnableOut to true.
Instruction first scan
N/A
Instruction first run
N/A
Postscan
N/A
FBD Function
Condition/State
Action Taken
Prescan
N/A
Normal Scan
Dest = Truncated value of the Source.
Instruction first run
N/A
Instruction first scan
N/A
Postscan
N/A
Example
Ladder Diagram
Function Block Diagram
FBD Block
FBD Function
Structured Text
REAL_dest := TRUNC(REAL_src);
Provide Feedback
Have questions or feedback about this documentation? Please submit your feedback here.