LTRUNC

LTRUNC 1:

The LTRUNC function determines the integral part of a floating point number.

Unlike TRUNC, the result from LTRUNC is of type LREAL and is therefore not limited to the value range of integer variables.

Examples

LTRUNC(2.8) = 2

LTRUNC(-2.8) = -2

FUNCTION LTRUNC : LREAL

LTRUNC 2: Inputs

VAR_INPUT
    lr_in : LREAL;
END_VAR

Name

Type

Description

lr_in

LREAL

Function parameters of type LREAL

LTRUNC 3:

Comparison with other rounding functions

Similar functions: TRUNC, CEIL, FLOOR

Example results of various rounding functions

x

0

0.4

0.5

0.6

1

1.4

1.5

1.6

1.78

FLOOR(x)

0

0

0

0

1

1

1

1

1

CEIL(x)

0

1

1

1

1

2

2

2

2

LTRUNC(x)

0

0

0

0

1

1

1

1

1

TO_LINT(x)

0

0

1

1

1

1

2

2

2

x

-1.78

-1.6

-1.5

-1.4

-1

-0.6

-0.5

-0.4

FLOOR(x)

-2

-2

-2

-2

-1

-1

-1

-1

CEIL(x)

-1

-1

-1

-1

-1

0

0

0

LTRUNC(x)

-1

-1

-1

-1

-1

0

0

0

TO_LINT(x)

-2

-2

-2

-1

-1

-1

-1

0

If you do not want to round to an integer value and instead want to round to a specific decimal place, this can be achieved by multiplying and dividing by a power of ten. The following example results show the rounding to the first decimal place.

x

0

0.04

0.05

0.06

0.1

0.14

0.15

0.16

0.178

FLOOR(x * 10) / 10

0

0

0

0

0.1

0.1

0.1

0.1

0.1

CEIL(x * 10) / 10

0

0.1

0.1

0.1

0.1

0.2

0.2

0.2

0.2

LTRUNC(x * 10) / 10

0

0

0

0

0.1

0.1

0.1

0.1

0.1

TO_LINT(x * 10) / 10.0

0

0

0.1

0.1

0.1

0.1

0.2

0.2

0.2

x

-0.178

-0.16

-0.15

-0.14

-0.1

-0.06

-0.05

-0.04

FLOOR(x * 10) / 10

-0.2

-0.2

-0.2

-0.2

-0.1

-0.1

-0.1

-0.1

CEIL(x * 10) / 10

-0.1

-0.1

-0.1

-0.1

-0.1

0

0

0

LTRUNC(x * 10) / 10

-0.1

-0.1

-0.1

-0.1

-0.1

0

0

0

TO_LINT(x * 10) / 10.0

-0.2

-0.2

-0.2

-0.1

-0.1

-0.1

-0.1

0

Requirements

Development environment

Target system type

PLC libraries to include

TwinCAT v3.0.0

PC or CX (x86)

Tc2_Math