Learn PLCs free
Type ConversionBeginnerIEC 61131-3

REAL_TO_INT (Real to Integer Conversion)

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). 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

Ladder Logic Example

// Ladder Logic - REAL_TO_INT (Analog Output)
//
// |----[MUL]----[REAL_TO_INT]----|
// | Calculation  IN: Scaled_Val  |
// | result       OUT: AO_Value   |

Structured Text Example

// Convert calculated value to analog output
Scaled_Val := PID_Output * 27648.0;
AO_Value := REAL_TO_INT(Scaled_Val);
// Note: 25.7 rounds to 26, 25.5 rounds to 26

20 Production-Ready Ladder Logic Templates

Stop writing the same rungs from scratch. Get copy-paste-ready templates for motor control, PID loops, safety interlocks, conveyors, and more.

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.

Stop Writing Ladder Logic From Scratch

Get 20 production-ready ladder logic templates for $29 -- download instantly and use them on your next project today.

20
Ready-Made Templates
LD + ST
Both Languages Included
$29
One-Time Purchase
Get Instant Access -- $29

Instant download - 30-day money-back guarantee - Use on unlimited projects

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 →