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
| Name | Type | Description |
|---|---|---|
| IN | REAL | Floating-point value to convert |
Outputs
| Name | Type | Description |
|---|---|---|
| OUT | INT | Rounded 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
Siemens (TIA Portal)
Use CONVERT or REAL_TO_INT in TIA Portal. Uses round-half-even (banker's rounding).
Allen-Bradley (Studio 5000)
Use TRUNC for truncation or RND for rounding before integer conversion.
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.
Related Function Blocks
INT_TO_REAL (Integer to Real Conversion)
Converts 16-bit integer to 32-bit floating-point real value.
View Reference →BOOL_TO_INT (Boolean to Integer Conversion)
Converts FALSE to 0 and TRUE to 1 for numeric operations.
View Reference →INT_TO_STRING (Integer to String Conversion)
Converts integer value to its decimal string representation for display or logging.
View Reference →ANY_TO_ANY (Universal Type Conversion)
General type conversion framework covering all IEC 61131-3 type conversion functions.
View Reference →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.
Instant download - 30-day money-back guarantee - Use on unlimited projects