Glossary

What is Integer division?

Dividing two integers in ST gives an integer and the fraction is dropped, which is a common cause of an unexpected zero.

The classic case: Percent := Raw / 27648 * 100; gives zero because the division runs first and yields zero. Convert to REAL first, or write the constants as reals: 27648.0.

The same trap appears in ratios, rates and averages. In any calculation with fractions, make sure at least one side is REAL.

Related terms

Type conversion
Explicit functions that move a value between types, such as INT_TO_REAL, REAL_TO_INT, TRUNC and TIME_TO_DINT.
Operator precedence
The order an expression is evaluated in: brackets, then negation, then multiply and divide, then add and subtract, then comparisons, then AND, XOR and OR.

All terms