TRUNC_TO_UDINT

Truncate (cut off) decimal digits of REAL or LREAL input variable, convert to unsigned DOUBLE INTEGER

TRUNC_TO_UDINT cuts off the digits following the decimal of a REAL, LREAL number and delivers an output variable of the data type Unsigned 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 (UDINT)

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
		UDINT_value: UDINT:=0;
		REAL_value: REAL:=78497.79;
	END_VAR

LD body

BODY
    WORKSPACE
        NETWORK_LIST_TYPE := NWTYPELD ;
        ACTIVE_NETWORK := 0 ;
    END_WORKSPACE
    NET_WORK
        NETWORK_TYPE := NWTYPELD ;
        NETWORK_LABEL :=  ;
        NETWORK_TITLE :=  ;
        NETWORK_HEIGHT := 6 ;
        NETWORK_BODY
B(B_F,TRUNC_TO_UDINT!,Instance,13,2,23,4,,?D?C);
B(B_VARIN,,REAL_value,11,2,13,4,);
B(B_VAROUT,,UDINT_value,23,2,25,4,);
L(1,0,1,6);
        END_NETWORK_BODY
    END_NET_WORK
END_BODY

ST body

UDINT_value := TRUNC_TO_UDINT(REAL_value);

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