TRUNC_TO_DINT

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.

NOTE
  • 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.

Parameters

Input

Unnamed input (REAL, LREAL)

Input data type

Output

Unnamed output (DINT)

Conversion result

Error flags

sys_bIsOperationErrorHold (turns to TRUE and remains TRUE)

if input variable does not have the data type REAL

sys_bIsOperationErrorNonHold (turns to TRUE for one scan)

output variable is greater than a 32-bit DOUBLE INTEGER

sys_bIsCarry (turns to TRUE for one scan)

if output variable is zero

Example

POU header

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.

POU body

The decimal digits of REAL_value are cut off. The result is stored as a 32-bit DOUBLE INTEGER in DINT_value.

LD body

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

ST body

DINT_value:=TRUNC_TO_DINT(REAL_value);

IL body

LD

REAL_value

TRUNC_TO_DINT

ST

DINT_value

Modified on: 2022-08-23Feedback on this pagePanasonic hotline