Truncation

Help Contents

Introduction

The Truncation functions convert real values to integers by rounding to the next integer closest to zero.

You can declare truncation in three different ways:

FormSyntaxDescription
Exactly Typed *_TRUNC_** Where * is the type to change from, and ** is the type to change to.
For example: REAL_TRUNC_INT( 12.5 )
Overloaded #1 ANY_TRUNC_** Where ** is the type to change to.
For example: ANY_TRUNC_INT( 12.5 )
Overloaded #2 TRUNC_** Where ** is the type to change to.
For example: TRUNC_INT( 12.5 )

The from (*) type can be REAL or LREAL. The to (**) type can be SINT, USINT, INT, UINT, DINT, UDINT, LINT, or ULINT.

Examples of floating point rounding using REAL_TRUNC_INT( X ):

Floating PointRounded Integer Result
REAL#3.6INT#3
REAL#3.5INT#3
REAL#3.4INT#3
REAL#2.5INT#2
REAL#1.5INT#1
REAL#-1.5INT#-1
REAL#-2.5INT#-2
REAL#-3.4INT#-3

Standards Compliance

Table 22.2 - IEC 61131-3 Second Edition.

Table 22.2 - IEC 61131-3 Third Edition.

Further Information

Elementary Data Type

To learn about the standard elementary data types.

Type Casts

To learn about other methods of converting from real numbers to integers.

Conversion Functions

For a summary of all conversion functions.

Common Elements

To learn about other common language elements.

Glossary

For the meaning of terms used in Fernhill SCADA.