free quality report for PLCopenXML exports

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

Bad: the rule fires
PROGRAM ScaleVAR    iRaw : INT;    rLevel : REAL;END_VARrLevel := iRaw / 10;
Fixed: the rule is silent
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

  1. Cast to REAL: r := INT_TO_REAL(x) / N.0;
  2. Or divide by a real constant: x / 10.0 instead of x / 10.
Check your project

Upload a PLCopen XML or CODESYS .export file: the report is free and the code is not stored.

Local version on GitHub →

The same linter without uploading a file: command line and GitHub Action.

Related rules

In-depth article

2026-11-26

Processing happens in memory, and the uploaded code is not stored. The tool advises; code changes are up to the engineer (see what the linter can't see). What happens to your code → · Rule reference · Your code & privacy · Industry benchmark · Feedback · GitHub