Truncate (cut off) decimal digits of REAL or LREAL input variable, convert to INTEGER
TRUNC_TO_INT cuts off the decimal digits of a REAL, LREAL number and delivers an output variable of the data type INTEGER.
Input
Input data type
Output
Conversion result
If the required data type is supported, we recommend using the overloaded instruction TO_INT
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.
if input variable does not have the data type REAL
if output variable is greater than a 16-bit INTEGER
if input variable does not have the data type REAL
if output variable is greater than a 16-bit INTEGER
if output variable is zero
All input and output variables used for programming this function have been declared in the POU header. The same POU header is used for all programming languages.
VAR
REAL_value: TRUNC;
INT_value: INT:=0;
END_VAR
This example uses variables. You can also use a constant for the input variable.
The decimal digits of REAL_value are cut off. The result is stored as a 16-bit INTEGER in INT_value.
BODY
WORKSPACE
NETWORK_LIST_TYPE := NWTYPELD ;
ACTIVE_NETWORK := 0 ;
END_WORKSPACE
NET_WORK
NETWORK_TYPE := NWTYPELD ;
NETWORK_LABEL := ;
NETWORK_TITLE := ;
NETWORK_HEIGHT := 2 ;
NETWORK_BODY
B(B_F,TRUNC_TO_INT!,Instance,10,0,19,2,,?D?C);
B(B_VARIN,,REAL_value,8,0,10,2,);
B(B_VAROUT,,INT_value,19,0,21,2,);
L(1,0,1,2);
END_NETWORK_BODY
END_NET_WORK
END_BODY
INT_value:=TRUNC_TO_INT(REAL_value);
LD |
REAL_value |
TRUNC_TO_INT |
|
ST |
INT_value |