Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

E163 - Implicit float to integer conversion truncates

A floating point value is converted implicitly to an integer type. The fractional part is lost, and a value outside the range of the integer type has no defined result.

Code example:

PROGRAM mainProg
VAR
    measured : REAL := 2.7;
    whole : LINT;
END_VAR
    whole := measured;     // warning: the result is 2
END_PROGRAM

To silence the warning, convert explicitly:

    whole := REAL_TO_LINT(measured);