REAL to Integer
To convert a REAL value to an integer value, the controller rounds the fractional part and truncates the upper portion of the non-fractional part. If data is lost, the controller sets the overflow status flag. Numbers round as follows:
- Numbers other than x.5 round to the nearest whole number.
- X.5 rounds to the nearest even number.
The following example show the result of converting REAL values to DINT values.
For example, the conversion of REAL values to DINT values:
This REAL value: | Converts to this DINT value: |
-2.5 | -2 |
-1.6 | -2 |
-1.5 | -2 |
-1.4 | -1 |
1.4 | 1 |
1.5 | 2 |
1.6 | 2 |
2.5 | 2 |
Important: | The arithmetic status flags are set based on the value being stored. Instructions that normally do not affect arithmetic status keywords might appear to do so if type conversion occurs because of mixed data types for the instruction parameters. The type conversion process sets the arithmetic status keywords. |
Provide Feedback