Your PLC Math Is Right—So Why Did the Decimal Disappear?
- PLC Play Ground
- 0
- Posted on
A calculation can lose its fractional part before the result ever reaches a REAL destination. Check the types used by the operation itself, including intermediate expressions. Changing the final display to show more decimal places cannot recover information already discarded.
Original arithmetic example; quotient and conversion behavior are instruction-specific.
What is happening?
Integer arithmetic, conversion, and rounding rules depend on the instruction and platform. Some instructions return a whole quotient and separate remainder; others convert according to documented rules. Make the intended numerical representation explicit at the stage where division occurs, rather than assuming the destination decides everything.
Check these five things
-
List the declared type of each operand, literal, intermediate result, and destination. Include values supplied by an HMI or recipe.
-
Read the exact division and conversion instruction documentation for the controller and language. Do not transfer rounding assumptions between families.
-
Calculate a noninteger test case by hand and observe each intermediate value in simulation.
-
Use the supported explicit conversion or typed operation before division where fractional arithmetic is required.
-
Test small values, negative values where valid, and the largest expected numerator and denominator before accepting the change.
Worked example
In a teaching model using truncating integer division, 3 divided by 2 produces 1. Converting that result to REAL produces 1.0, not 1.5. Performing the division with an appropriate floating-point operation preserves the fractional result. Verify the actual instruction rather than assuming all PLC integer divisions truncate.
Quick diagnostic reference
| Stage | Question |
|---|---|
| Inputs | Are both operands integers? |
| Operation | Which arithmetic rules apply? |
| Destination | Is precision already lost? |
The mistake to avoid
Multiplying by a scale factor first may preserve useful resolution but can also overflow an intermediate integer. Check the entire expression's range.
How to verify the fix
Document expected and actual results for representative fractions and boundary values, with the operation types visible in the test record.
Field-work boundary: These are educational diagnostic guides. Use the exact equipment manuals and approved site procedures. Electrical testing and machinery changes belong to qualified, authorized personnel; control hazardous energy and validate affected functions before release.
Technical reference
Siemens: 16-bit integer division in S7-1500 STL. The examples and diagnostic tables above are original teaching material; they do not replace the product manual.
