Truncate (cut off) decimal digits of REAL or LREAL input variable, convert to DOUBLE INTEGER
TRUNC_TO_DINT cuts off the decimal digits of a REAL, LREAL number and delivers an output variable of the data type DOUBLE INTEGER.
If the decimal digits are cut off, positive numbers will be decreased towards zero and negative numbers will be increased towards zero.
Since REAL numbers only have a resolution of about 7 digits, information for large numbers will be lost.
Input
Input data type
Output
Conversion result
if input variable does not have the data type REAL
output variable is greater than a 32-bit DOUBLE 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;
DINT_value: DINT:=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 32-bit DOUBLE INTEGER in DINT_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_DINT!,Instance,10,0,19,2,,?D?C);
B(B_VARIN,,REAL_value,8,0,10,2,);
B(B_VAROUT,,DINT_value,19,0,21,2,);
L(1,0,1,2);
END_NETWORK_BODY
END_NET_WORK
END_BODY
DINT_value:=TRUNC_TO_DINT(REAL_value);
LD |
REAL_value |
TRUNC_TO_DINT |
|
ST |
DINT_value |