Problem Overview: Floating-Point Values and HMI Display
Engineers frequently encounter a numerical display anomaly when commissioning Siemens S7-1200 or S7-1500 PLCs against a SIMATIC HMI panel: the PLC calculates a real number to two decimal places, but the HMI tag field shows 0.2 instead of 0.20. The two notations are mathematically identical because IEEE 754 single-precision floating point has no concept of trailing zeros. The PLC stores the bit pattern that corresponds to the value 0.2 exactly; whether the operator sees one or two decimal places on the screen is determined entirely by the format pattern configured on the HMI tag or IO field, not by the value in the PLC data block.
This article documents the two-step resolution: (1) round the real number deterministically inside the PLC using the CALCULATE instruction with the ROUND function, and (2) configure the HMI IO field format pattern to render exactly two fractional digits. The procedure applies to KTP400 Basic, KTP700 Basic, KTP1200 Basic, Comfort Panels, and WinCC Runtime Advanced / Professional targets. See the S7-1200 product page and the TIA Portal product page for platform-specific documentation.
Prerequisites
- Siemens SIMATIC S7-1200 CPU or S7-1500 CPU. Both instruction sets support the CALCULATE and ROUND operators described in this article.
- STEP 7 Basic / Professional V13 SP1 or higher in TIA Portal. The CALCULATE instruction and the format pattern string editor are available from V13 SP1 onward.
- A SIMATIC HMI panel: KTP400 Basic, KTP700 Basic, KTP1200 Basic, KTP400 Comfort, KTP700 Comfort, KTP900 Comfort, KTP1200 Comfort, TP Comfort, or a WinCC Runtime PC target.
- An HMI connection configured between the PLC and HMI (Ethernet / PROFINET, PROFIBUS, or MPI).
- A tag of data type
Real(32-bit IEEE 754) wired to the IO field. If the source value is generated from a sensor, scale it in a separate FC before applying the rounding step.
Why 0.2 Equals 0.20 Inside the PLC
A Real tag in the S7-1200 / S7-1500 occupies 32 bits and conforms to IEEE 754 single precision: 1 sign bit, 8 exponent bits, 23 mantissa bits. The decimal value 0.2 cannot be represented exactly in binary; the closest representable value is 0.20000000298023223876953125. The closest value to 0.20 is exactly the same bit pattern. The trailing zero in 0.20 carries no mathematical meaning, so the CPU stores a single normalized real regardless of how the engineer thinks of the value.
Equivalent behavior can be observed in any language that uses IEEE 754: C, C++, Java, Python, MATLAB, and LabVIEW all collapse 0.2 and 0.20 to the same bit pattern. The display difference is always a formatting problem, never a calculation problem. Fixing the value to two decimals on the PLC side is therefore an explicit engineering choice driven by display consistency and audit-trail readability.
Method 1 — Rounding with the CALCULATE Instruction
The fastest deterministic round-to-two-decimal-places method is to scale up by 100, round to integer, then scale down by 100. The CALCULATE box in TIA Portal allows this without writing SCL:
CALCULATE(ROUND(IN1 * IN2) / IN2)
Where:
-
IN1— the input tag of typeRealthat should be rounded (for example,"DB_Math".Scaling.Value). -
IN2— the scaling factor of typeRealthat defines the rounding resolution. Use100.0for two decimals,1000.0for three decimals,10.0for one decimal.
Step-by-Step Procedure
- Open the PLC program block (OB, FB, or FC) in TIA Portal.
- From the Instructions pane under Basic Instructions → Math functions, drag CALCULATE into the network.
- Click the function box. The default output is a generic
Real; click the small + icon to confirm the output and rename it (e.g.,RoundedValue). - In the Formula editor, type
ROUND(IN1*IN2)/IN2. The CALCULATE compiler auto-detects inputsIN1andIN2and exposes them as input pins on the box. - Wire
IN1to the source tag (the un-rounded real) andIN2to a constant100.0(or a tag if you want dynamic resolution). - Wire the output to a destination tag, e.g.,
"DB_Display".HMI_RoundedValue. - Compile the block and download it to the CPU.
The intermediate value ROUND(IN1 * 100.0) yields a DInt or LReal depending on the ROUND variant used. The division by 100.0 re-promotes the result to Real and preserves up to two fractional digits within the typical float error range.
CALCULATE Behavior Table
| IN1 (Real) | IN2 (Real) | ROUND(IN1*IN2) | Final (Real) | Expected |
|---|---|---|---|---|
| 0.0 | 100.0 | 0 | 0.0 | 0.00 |
| 0.23456 | 100.0 | 23 | 0.23 | 0.23 |
| 0.245 | 100.0 | 25 (banker's round)* | 0.25 | 0.25 |
| 0.255 | 100.0 | 26 (away-from-zero)* | 0.26 | 0.26 |
| 1.99999 | 100.0 | 200 | 2.0 | 2.00 |
| -0.23456 | 100.0 | -23 | -0.23 | -0.23 |
ROUND in TIA Portal can switch between "round half away from zero" and "round half to even" (banker's rounding) depending on firmware version. Confirm the round mode in your project by forcing a known half-value (e.g., 0.245) and verifying the output. Refer to the Siemens Industry Online Support portal for the firmware-specific change log of the S7-1200 / S7-1500 system manuals.Method 2 — Direct SCL with Explicit Type Casting
If the application runs SCL instead of LAD/FBD, the same logic in a one-liner looks like this:
"DB_Display".HMI_RoundedValue :=
DINT_TO_REAL(REAL_TO_DINT("DB_Math".Scaling.Value * 100.0)) / 100.0;
This avoids the CALCULATE box and is easier to step through in the SCL debugger. The REAL_TO_DINT conversion calls the same underlying rounding primitive as ROUND. Add a final IF guard to handle NaN propagation when the source value is uninitialized or comes from a faulty sensor.
Method 3 — Truncation, Floor, and Ceiling Variants
If the application requires a non-symmetric round (always down for positives, up for negatives), use the TRUNC, FLOOR, or CEIL instructions instead of ROUND:
CALCULATE(TRUNC(IN1 * IN2) / IN2) // truncate toward zero
CALCULATE(FLOOR(IN1 * IN2) / IN2) // round toward negative infinity
CALCULATE(CEIL(IN1 * IN2) / IN2) // round toward positive infinity
These variants are commonly used in dosing and batch applications where an under-dose is more dangerous than an over-dose, or where a stored-quantity calculation must never exceed the available inventory.
| Instruction | Behavior at x.5 | Typical Use Case |
|---|---|---|
| ROUND | Round half to nearest (mode depends on firmware) | General display rounding |
| CEIL | Always round up | Dosing, minimum quantity calculations |
| FLOOR | Always round down | Inventory, storage calculations |
| TRUNC | Truncate toward zero | Display truncation, integer parts |
Configuring the HMI IO Field for Two-Decimal Display
The PLC rounding step is necessary but not sufficient. Without an HMI-side format pattern, the IO field will still render 0.20 as 0.2 on the screen. The format pattern is a string that uses the tokens 9, 0, the decimal separator, and the thousands separator to define how the runtime formats the tag value. TIA Portal exposes this pattern under the IO field's properties in the inspector window.
Format Pattern Tokens
| Token | Meaning |
|---|---|
9 |
Digit placeholder. Displayed only if a non-zero digit occupies the position. |
0 |
Digit placeholder. Always displayed, even when zero. |
. |
Decimal separator. Use the locale-specific character (in English, .; in German, ,). |
, |
Thousands separator. Optional. |
; |
Pattern separator between positive and negative sub-patterns. |
E+0 |
Scientific notation suffix. |
Common Format Patterns for Two-Decimal Display
| Pattern | PLC Value 0.2 Renders As | PLC Value 1.234 Renders As | PLC Value 1234.5 Renders As |
|---|---|---|---|
99.99 |
0.20 | 1.23 | 1234.50 |
0.00 |
0.20 | 1.23 | 1234.50 |
9.99 |
.20 | 1.23 | 1234.50 |
0.0## |
0.2 | 1.234 | 1234.5 |
0.00## |
0.20 | 1.234 | 1234.50 |
#,##0.00 |
0.20 | 1.23 | 1,234.50 |
The pattern 99.99 is the most commonly used in SIMATIC HMIs and is documented in the TIA Portal help under WinCC → Configuring displays → Output formats for IO fields. It produces up to two integer digits with a leading zero only if necessary, and exactly two fractional digits. The pattern 0.00 is functionally equivalent for the values shown above and is preferred when the engineer wants the leading zero explicitly anchored.
Step-by-Step: Setting the Format Pattern on a KTP400 Basic
- In the TIA Portal project tree, expand HMI → Screens and double-click the screen that contains the IO field bound to the rounded tag.
- Click the IO field in the editor to select it.
- In the inspector window (right side), open the Properties tab.
- Under General, locate the Process value row and confirm the tag binding points to the rounded destination tag (e.g.,
"DB_Display".HMI_RoundedValue). - Click Properties → Appearance (or in older TIA Portal versions, Display → Format).
- Find the Format / Format pattern field. Replace the existing pattern (typically
999) with99.99or0.00. - For numeric fields, ensure the Representation is set to Decimal, not Binary or Hexadecimal.
- Compile the HMI project and download to the panel.
Step-by-Step: KTP700 / KTP1200 / Comfort Panels
- Open the screen and select the IO field.
- Inspector → Properties → General → Display → Format pattern.
- Enter
99.99. The field accepts up to 16 characters; the pattern length is unlimited within that limit. - Under Layout → Display, the Number of decimal places field is automatically updated by the format pattern; you can also set it manually for legacy projects.
- Compile and download.
Verification Procedure
After downloading the modified PLC and HMI programs, perform these checks:
- Open a watch table in TIA Portal and force the source tag to
0.0,0.23456, and0.255in sequence. Verify the rounded tag displays0.00,0.23, and0.26(or0.25depending on round mode). - Toggle the PLC to RUN mode and watch the HMI IO field on the live panel. Confirm the visible value matches the expected two-decimal form.
- If the panel still shows a single-decimal value, check that the format pattern field actually contains the change. A plain HMI compile does not always pick up string-only changes; perform a manual HMI download.
- Cycle power to the panel to ensure the format pattern is loaded from the project's compiled RT data, not from a cached project file on the panel's internal storage.
- Repeat the test with a negative value (e.g.,
-0.23456) to confirm the negative-sign placement is correct.
Troubleshooting Matrix
| Symptom | Likely Cause | Corrective Action |
|---|---|---|
| IO field shows 0.2 instead of 0.20 | Format pattern is "99.9" or default "999" | Change to "99.99" or "0.00" |
| IO field shows ".20" (no integer digit) | Pattern is "9.99" | Use "99.99" or "0.00" |
| PLC tag shows 0.20000003 instead of 0.20 | Floating-point representation; not actually a bug | Use ROUND or format pattern to limit visible digits |
| IO field shows "######" | Pattern width too small for the value | Increase the number of "9" tokens (e.g., "9999.99") |
| IO field shows 0 instead of 0.20 | Pattern integer width too small | Ensure at least one leading "9" or "0" before the decimal |
| Trailing zeros not shown after restart | Format pattern not downloaded to panel | Force re-compile and re-download HMI project |
| Round direction changes after firmware update | Banker's rounding introduced in newer firmware | Validate against expected behavior; adjust logic if needed |
| Format pattern reverts to default after compile | Tag type mismatch (LReal vs Real) | Match the tag data type in the DB and HMI tag |
| Comma displayed instead of dot on screen | Panel runtime locale uses a different decimal separator | Change the panel language settings or use the locale-independent format pattern |
| Pattern ignored on KTP400 Basic V12 firmware | Pre-V13 firmware has limited format pattern support | Upgrade the panel firmware to V13+ or set the manual "Decimal places" property to 2 |
Negative Numbers and Sign Placement
For values that may be negative (e.g., a deviation reading), the format pattern must include the minus sign position. Use -99.99 for symmetric display or 99.99;-99.99 for explicit positive / negative sub-patterns. The semicolon separates the positive and negative sub-patterns. For zero, the runtime always uses the positive sub-pattern.
For values that can exceed 999.99, increase the integer part of the pattern:
99999.99 // up to 5 integer digits, exactly 2 fractional
-99999.99 // symmetric negative
#,##0.00 // thousands separator, exactly 2 fractional
Alternative: Pre-Format the Value as a String in the PLC
When the HMI runtime is limited (e.g., very old WinCC flexible panels or projects migrated from ProTool), the PLC can convert the rounded real to a String using the SCL Real_TO_String_Fmt function with an explicit format. The string then drives a symbolic IO field with the text representation. This bypasses format pattern limitations but is more memory-intensive (a 7- to 12-byte string per value).
"DB_Display".HMI_StringValue := Real_TO_String_Fmt(
IN := "DB_Display".HMI_RoundedValue,
FORMAT := 1, // 1 = fixed-point notation
PRECISION := 2 // 2 fractional digits
);
The Real_TO_String_Fmt function is available in the S7-1500 instruction set and in S7-1200 firmware V4.0 onward. It produces a left-padded string such as " 0.20" or "123.45" directly, which can be displayed in a text-only IO field without any pattern editing.
Performance and Scan-Time Considerations
The CALCULATE instruction with ROUND adds three floating-point operations per call. On an S7-1200 CPU 1214C, the worst-case execution time is in the single-digit microsecond range. On an S7-1500 CPU 1515-2 PN, it is below 1 microsecond. For a tag refreshed every 100 ms in a WinCC cycle, this overhead is negligible.
For high-frequency updates (sub-millisecond), pre-compute the rounded value once in OB1 and store it in a separate DB, then bind the HMI tag to the pre-computed tag. Avoid binding the IO field directly to the CALCULATE output, because the runtime would have to re-evaluate the formula on every HMI poll. For multi-instance applications, place the rounding inside a multi-instance FB so that the IEC timer / counter overhead is amortized.
Edge Cases and Field-Proven Caveats
-
Division by zero:
IN2must not be 0. Validate it using a comparator before calling CALCULATE, or use a safe-default value via a MOVE fallback. -
NaN propagation: If the source real is uninitialized or comes from a faulty sensor, the rounding may propagate NaN through the output. Add a range check (e.g.,
IF Value <> Value THEN) to detect NaN explicitly. -
Decimal separator on the HMI: The pattern uses
.as the decimal separator, but the panel's runtime locale controls the actual character shown. To force a dot regardless of locale, configure the panel language under HMI → Runtime settings → Language & Font. - Watch table vs HMI: When monitoring the DB in TIA Portal online view, the value is always shown with default formatting. The HMI is the only place where the format pattern is applied.
-
Pattern length limit: KTP400 Basic accepts a maximum of 16 characters in the format pattern.
99.99uses 5 characters, well within the limit. For longer patterns (e.g.,#,##0.00;-#,##0.00), use a Comfort Panel or PC Runtime instead. - Cached HMI project: If the panel has been running a prior project for months, a partial download may leave the old format pattern in volatile memory. Always perform a full HMI transfer during commissioning.
-
Read-only IO fields: The format pattern applies to the displayed value. If the IO field is configured as an output, the operator-entered value is parsed against the same pattern, so an operator who types
0.2will have it parsed to0.20on the next read cycle.
Frequently Asked Questions
Why does the PLC show 0.2 instead of 0.20 in the watch table?
The watch table in TIA Portal uses the default Real display format, which suppresses trailing zeros. The actual stored value is identical between 0.2 and 0.20 because IEEE 754 single-precision has no trailing-zero concept. Configure a custom display format in the watch table or look at the HMI's IO field instead.
Is the CALCULATE(ROUND(IN1*IN2)/IN2) method the only way to round?
No. You can use SCL with DINT_TO_REAL / REAL_TO_DINT conversion, the TRUNC / FLOOR / CEIL instructions for non-standard rounding, or the Real_TO_String_Fmt function to skip HMI formatting entirely. The CALCULATE approach is preferred for ladder / FBD programmers because it requires no SCL block.
Does the rounding mode change between S7-1200 firmware versions?
Yes. Pre-V4.2 S7-1200 and pre-V2.0 S7-1500 round half away from zero. Post those versions, the CPU uses round half to even (banker's rounding) per IEEE 754. Verify the behavior in your project with a forced value of 0.245 and 0.255 and compare against expected outputs. Check the Siemens Industry Online Support portal for the firmware-specific change log.
Can I use a global format pattern for all IO fields on the panel?
Yes. Under HMI → Runtime settings → Language & Font you can set the default number format. Each individual IO field can override this default. Set the default to 99.99 for consistent two-decimal display across the entire project, then override per field when a different resolution is needed.
What if my KTP400 Basic is firmware V12 or older and ignores the format pattern?
Pre-V13 Basic Panels have limited format pattern support. Use the manual "Decimal places" property (set to 2) and pair it with a SCL pre-formatted string tag, or upgrade the panel firmware to V13 or higher where the full format pattern string is respected.
How do I round to 3 or 4 decimal places for laboratory or pharmaceutical applications?
Change IN2 to 1000.0 (3 decimals) or 10000.0 (4 decimals) and set the HMI format pattern to 99.999 or 99.9999 respectively. For values in the 0.001 to 0.0001 range, use the 0.000 pattern to anchor the leading zero.