TRUNC block

Short summary

Name

TRUNC

→POU type

→function

Category

IEC-block, ConvertEnh

Conform to →IEC-standard

images/s/b2ic8e/9012/1ca6q62/_/images/icons/emoticons/add.svg not defined in IEC-standard

Graphical interface

images/download/thumbnails/414781183/TRUNC-version-1-modificationdate-1534930075697-api-v2.png

Available since

  • version 1.27.0 (for logi.CAD 3)

  • version 3.1.0 (for library Standard) – For inputs of data type REAL, the optimized float variant of the C-runtime is used. Compared to previous versions , it is possible that (marginal) other results are returned within the threshold range of the block.

Functionality

The mathematical function trunc is called:

The decimal portion of the floating-point number connected to input IN is truncated (there is no rounding). The block returns the integer value as a REAL or LREAL value.

Compare: TRUNC blocks according to IEC-standard (listed under "Convert").

Inputs, return value


Identifier

→Data type

Description

Inputs:

IN

REAL, LREAL
(corresponds to →generic data type ANY_REAL)

value to truncate

Return value:

REAL, LREAL
(corresponds to →generic data type ANY_REAL)


Input EN and output ENO are available when →calling the block. See "Execution control: EN, ENO" for information on input EN and output ENO.

Example for usage within ST-editor

PROGRAM Test
VAR
result1, result2, result3, result4, result5, result6, result7, result8 : REAL;
END_VAR
result1 := TRUNC(2.8); (* The variable 'result1' evaluates to '2.0'. *)
result2 := TRUNC(2.5); (* The variable 'result2' evaluates to '2.0'. *)
result3 := TRUNC(2.01); (* The variable 'result3' evaluates to '2.0'. *)
result4 := TRUNC(2.0); (* The variable 'result4' evaluates to '2.0'. *)
result5 := TRUNC(-2.0); (* The variable 'result5' evaluates to '-2.0'. *)
result6 := TRUNC(-2.3); (* The variable 'result6' evaluates to '-2.0'. *)
result7 := TRUNC(-2.5); (* The variable 'result7' evaluates to '-2.0'. *)
result8 := TRUNC(-2.99); (* The variable 'result8' evaluates to '-2.0'. *)
END_PROGRAM

When creating your application within the ST-editor, enter a call of a block by typing the text as requested by the syntax or use Content Assist.