TRUNC_TO_INT

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.

Parameters

Input

Unnamed input (REAL, LREAL)

Input data type

Output

Unnamed output (INT)

Conversion result

Remarks

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

Error flags

sys_bIsOperationErrorHold (turns to TRUE and remains TRUE)
  • if input variable does not have the data type REAL

  • if output variable is greater than a 16-bit INTEGER

sys_bIsOperationErrorNonHold (turns to TRUE for one scan)
  • if input variable does not have the data type REAL

  • 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
		REAL_value: TRUNC;
		INT_value: INT:=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 16-bit INTEGER in INT_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_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

ST body

INT_value:=TRUNC_TO_INT(REAL_value);

IL body

LD

REAL_value

TRUNC_TO_INT

ST

INT_value

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