CEIL

The CEIL function determines an integer value from a floating point number that is lower than or equal to that number. It is always rounded up to the larger number.
The resulting number is of type LREAL
and is therefore not limited to the value range of integer variables.
Examples
FLOOR(2.8) = 3
FLOOR(-2.8) = -2
FUNCTION CEIL : LREAL
Inputs
VAR_INPUT
lr_in : LREAL;
END_VAR
Name | Type | Description |
---|---|---|
lr_in | LREAL | Function parameters of type LREAL |
Comparison with other rounding functions
Similar functions: FLOOR, TRUNC, LTRUNC
![]() | Unlike CEIL, the LTRUNC function always determines the integral part of a number. For positive values, this number is lower than or equal to the input parameter, for negative values it is greater than or equal to the input parameter. |
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 |
Prerequisites
Development environment | Target platform | PLC libraries to include |
---|---|---|
TwinCAT v3.1 >= 4026.13 | PC or CX (x86) | Tc2_Math >= v3.5.1.0 |