Rules / int-division
Integer division in Structured Text drops the fraction
An integer divided by an integer constant is an integer: iRaw / 10 with iRaw = 237 gives 23, not 23.7. The fraction is lost before the assignment, even when the target is REAL.
Severity: Warning
Rule id: int-division
Integer division (lost fraction?)
What the rule checks
Dividing an integer by an integer constant drops the fraction. Use /N.0 or *_TO_REAL if precision matters.
What it does to the plant
Analog scaling and flow calculations lose precision in steps: the loop hunts and totals drift apart.
Example
PROGRAM ScaleVAR iRaw : INT; rLevel : REAL;END_VARrLevel := iRaw / 10;
PROGRAM ScaleVAR iRaw : INT; rLevel : REAL;END_VARrLevel := INT_TO_REAL(iRaw) / 10.0;
Both listings are run through the linter by an automated test: the rule fires on the first and stays silent on the second.
How to fix
- Cast to REAL:
r := INT_TO_REAL(x) / N.0; - Or divide by a real constant:
x / 10.0instead ofx / 10.
Upload a PLCopen XML or CODESYS .export file: the report is free and the code is not stored.
The same linter without uploading a file: command line and GitHub Action.
Related rules
In-depth article
2026-11-26