Rules / real-to-time-mul
REAL_TO_TIME(x) * 1000 truncates the setpoint: 2.7 s becomes 2 s
REAL_TO_TIME treats the number as milliseconds and drops the fraction during conversion. A multiply after it scales a value that is already damaged. Multiply before converting: REAL_TO_TIME(x * 1000.0).
Severity: Warning
Rule id: real-to-time-mul
REAL_TO_TIME(...)*N truncates the setpoint
What the rule checks
REAL_TO_TIME treats the number as milliseconds and truncates the fraction before conversion, so fractional time setpoints are lost. Multiply before REAL_TO_TIME.
What it does to the plant
The operator adjusts a time setpoint and the machine runs a rounded-down value: pulses, pauses and delays are shorter than set.
Example
PROGRAM PulseVAR rPulseSec : REAL := 2.7; tPulse : TIME;END_VARtPulse := REAL_TO_TIME(rPulseSec) * 1000;
PROGRAM PulseVAR rPulseSec : REAL := 2.7; tPulse : TIME;END_VARtPulse := REAL_TO_TIME(rPulseSec * 1000.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
- Multiply BEFORE the conversion:
T := REAL_TO_TIME(sec * 1000.0); - Or:
T := DINT_TO_TIME(REAL_TO_DINT(sec * 1000.0));
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