Conversion instructions
153
Part II IEC Instructions
TRUNC_TO_INT
Truncate (cut off) decimal digits of REAL input variable, convert to
INTEGER
To add an enable input and enable output to the instruction, select [With EN/ENO] from the
"Instructions" pane (LD, FBD or IL editor). To reuse an instruction select "Recently used" from the
context menu or press <Ctrl>+<Shift>+<v> in the programming window.
PLC types
Availability of TRUNC_TO_INT (see page 1332)
If the decimal digits are cut off, positive numbers will be decreased
towards zero and negative numbers will be increased towards zero.
The first 16 bits of the input variable are assigned to the output
variable.
Data type I/O Function
REAL input input data type
INT output conversion result
No. IEC address Set If
R9007 %MX0.900.7 permanently input variable does not have the data
type REAL
R9008 %MX0.900.8 for an instant output variable is greater than a 16-bit
INTEGER
R9009 %MX0.900.9 for an instant output variable is zero
Description
TRUNC_TO_INT cuts off the decimal digits of a REAL number and delivers an output variable of
the data type INTEGER.
Data types
Error flags
Example
In this example, the same POU header is used for all programming languages. For an example
using IL (instruction list), please refer to the online help.
POU header
All input and output variables used for programming this function have been declared in the POU
header.
This example uses variables. You can also use a constant for the input variable.
Body
The decimal digits of REAL_value are cut off. The result is stored as a 16-bit INTEGER in
INT_value.
LD
ST
When programming with structured text, enter the following:
INT_value:=TRUNC_TO_INT(REAL_value);