TRUNC_TO_UINT

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

TRUNC_TO_UINT cuts off any digits following the decimal of a REAL, LREAL number and delivers an output variable of the data type Unsigned INTEGER.

Parameters

Input

Unnamed input (REAL, LREAL)

input data type

Output

Unnamed output (UINT)

Conversion result

Remarks

If the decimal digits are cut off, positive numbers will be decreased towards zero and negative numbers will be increased towards zero.

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)
  • if output variable is greater than a 16-bit 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
		UINT_value: UINT:=0;
		REAL_value: REAL:=28.5;
	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 := 5 ;
        NETWORK_BODY
B(B_VARIN,,REAL_value,13,2,15,4,);
B(B_VAROUT,,UINT_value,24,2,26,4,);
B(B_F,TRUNC_TO_UINT!,Instance,15,2,24,4,,?D?C);
L(1,0,1,5);
        END_NETWORK_BODY
    END_NET_WORK
END_BODY

ST body

UINT_value:=  TRUNC_TO_UINT(REAL_value);

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