Learn PLCs free
Type ConversionBeginnerIEC 61131-3

REAL to INT PLC Conversion: Rounding & Overflow

REAL-to-INT conversion changes a floating-point value into an integer value. It can round or truncate depending on the instruction and platform, and the result can overflow the target type. Choose the rounding rule explicitly, range-check before conversion and test negative x.5 values.

The REAL_TO_INT function converts a floating-point real value (REAL) to an integer value (INT). The fractional part is typically rounded to the nearest integer (banker's rounding in IEC 61131-3). Values outside the INT range (-32768 to 32767) may cause overflow. This conversion is used when calculation results need to be stored in integer registers, sent to analog outputs, or used as counter presets.

Parameters

Inputs

NameTypeDescription
INREALFloating-point value to convert

Outputs

NameTypeDescription
OUTINTRounded integer value

How REAL-to-integer conversion works scan by scan

Read the waveforms and state table together. The diagram shows the sequence; the table states what the program should observe at each execution.

REAL-to-INT conversion decision path

The REAL input is first checked against the target range, then an explicit rounding rule produces the integer destination. Overflow or invalid floating-point inputs follow the documented error path.

REAL-to-INT conversion decision pathThe REAL input is first checked against the target range, then an explicit rounding rule produces the integer destination. Overflow or invalid floating-point inputs follow the documented error path.REALRULEINTrange check + explicit rounding
Blue is the REAL source, amber marks the selected rounding or conversion rule, and green is the integer destination. Boundary and invalid-value behavior must be tested on the target controller.

State table

MomentInputInternal stateOutputEngineering meaning
In range, below halfREAL = 20.4Nearest-integer conversionINT = 20The fractional part is resolved by the selected nearest-integer rule.
In range, above halfREAL = 20.6Nearest-integer conversionINT = 21A rounding conversion differs from truncation, which would produce 20.
Exact halfREAL = 2.5 or -2.5Tie-breaking rule appliesPlatform/instruction dependentRockwell documents nearest-even behavior; never infer ties from one positive example.
Outside INT rangeREAL > 32,767 or < -32,768Overflow / error pathDo not consume as a valid resultRange-check or convert to a wider integer and inspect the documented status.

Ladder and Structured Text examples

Clamp an engineering value before conversion

|----[ ValueValid ]----[ LIM -32768.0 ScaledValue 32767.0 ]----|
|                         [ REAL_TO_INT ]                         |
|                         IN: ScaledValue                         |
|                         OUT: DisplayValue                       |

The range check protects the destination; it does not define rounding. Select a named conversion, ROUND, TRUNC, CEIL or FLOOR according to the engineering requirement.

Explicit rounding with range and validity checks

ConversionValid := NOT IsInvalidReal
    AND (ScaledValue >= -32768.0)
    AND (ScaledValue <= 32767.0);

IF ConversionValid THEN
    DisplayValue := REAL_TO_INT(ScaledValue);
ELSE
    DisplayValue := 0;
    ConversionFault := TRUE;
END_IF;

Replace the invalid-REAL check with the mechanism supported by the controller. If truncation is required, use the platform’s explicit truncation instruction instead of relying on an implicit cast.

Vendor compatibility

A shared mnemonic does not guarantee an identical interface or state machine. Confirm the instruction help for the controller, firmware, language and library version used on the project.

PlatformInstructionWhat maps cleanlyCaveat to verify
Rockwell LogixREAL-to-integer data conversionRounds to nearest; exact x.5 values round to the nearest even integerLoss of data sets the overflow status flag; the stored target type still determines range.
Siemens STEP 7 V21REAL_TO_INT / CONVERT; ROUND, CEIL, FLOOR, TRUNCREAL_TO_INT example rounds to nearest; separate instructions make other policies explicitENO is cleared for an out-of-range target or invalid floating-point value; verify CPU-specific behavior.
CODESYS / IEC-style runtimesREAL_TO_INT and conversion functionsExplicit type conversion is availableTie-breaking, overflow and invalid-value behavior must be read from the installed runtime/library documentation.

Failure modes and edge cases to test

Positive and negative x.5 values

Test 1.5, 2.5, -1.5 and -2.5. A nearest-even rule does not always round halves away from zero.

REAL just beyond target range

The conversion must take the defined fault or clamp path; a wrapped value is not acceptable process data.

NaN or infinity enters the calculation

Treat the input as invalid and follow the platform’s status behavior instead of displaying a plausible integer.

Implicit conversion inside another instruction

The language may convert silently and set arithmetic status. Make the conversion explicit at the data boundary.

Decimal display needs fixed precision

Do not convert away required precision. Store scaled integer counts or retain REAL and format only at presentation.

Verification checklist

  1. 1Write down whether the requirement is nearest, truncate, floor or ceiling.
  2. 2Test positive, negative, exact-half and nearly-half inputs.
  3. 3Test target minimum, maximum and one value beyond each boundary.
  4. 4Verify controller status or ENO behavior for invalid and out-of-range inputs.
  5. 5Confirm that the chosen integer type preserves the required engineering range and resolution.

Current primary and technical sources

These sources support the behavior summarized here. The exact controller, firmware, instruction and installed-library help remain authoritative for implementation.

Platform-Specific Implementation

S

Siemens (TIA Portal)

Use CONVERT or REAL_TO_INT in TIA Portal. Uses round-half-even (banker's rounding).

AB

Allen-Bradley (Studio 5000)

Use TRUNC for truncation or RND for rounding before integer conversion.

C

CODESYS

Use REAL_TO_INT() function. Rounds to nearest integer.

Common Applications

  • Analog output writing
  • Counter preset from calculation
  • Display value formatting
  • Register value storage
  • Setpoint rounding

Common Mistakes to Avoid

  • Not checking for overflow before conversion
  • Unexpected rounding behavior (banker's rounding)
  • Loss of precision for large values

Frequently Asked Questions

What is REAL_TO_INT (Real to Integer Conversion) in PLC programming?

Converts 32-bit floating-point value to 16-bit integer with rounding. The REAL_TO_INT function converts a floating-point real value (REAL) to an integer value (INT). The fractional part is typically rounded to the nearest integer (banker's rounding in IEC 61131-3).

What are common applications of REAL_TO_INT (Real to Integer Conversion)?

REAL_TO_INT (Real to Integer Conversion) is commonly used for: Analog output writing, Counter preset from calculation, Display value formatting, Register value storage, Setpoint rounding.

How do I use REAL_TO_INT (Real to Integer Conversion) in different PLC platforms?

Siemens: Use CONVERT or REAL_TO_INT in TIA Portal. Uses round-half-even (banker's rounding). Allen-Bradley: Use TRUNC for truncation or RND for rounding before integer conversion. CODESYS: Use REAL_TO_INT() function. Rounds to nearest integer.

Free PLC simulator

Wire this block up and run it

Drop the instruction into a rung, hit Run, and watch it execute in your browser. 12 guided lessons across 8 PLC dialects — free account, no credit card.

Practice PLCs free →