Rounding of numeric fields (sys.Rounding)ΒΆ
sys.Rounding,,i1 |
Determines if fractions are rounded to nearest integer |
Determines whether the fractional part of floating point fields and fixed point number fields is to be rounded to the nearest integer upon assignment to integer fields. May be set to OFF or ON.
If sys.Rounding is OFF, then the fractional part of a real number is removed when it is assigned to an integer. The number is simply truncated, and the result is always the nearest integer to zero from the floating point number.
If sys.Rounding is ON, then 0.5 is added to the floating point number before truncation. This causes the fractional part to be rounded to the nearest whole integer, whether upwards or downwards.
For example, if the value 5.4 is assigned to an integer field, the result is 5, whether sys.Rounding is OFF or ON. If it is ON, then 0.5 is added, making 5.9. But when the fractional part is dropped the result is still 5. However if 5.6 is assigned to an integer field, it results in 5 with sys.Rounding OFF, and in 6 with sys.Rounding ON. The addition of 0.5 has increased the value before truncation to 6.1.
By default, sys.Rounding is OFF.
Rounding also affects data assignation from floating point to n.d type fields where the number of decimal places to be stored is represented by .d. The decimal part is only rounded if sys.Rounding is ON.
NOTES
With rounding on, a value ending in .5 normally rounds upwards. This cannot, however, be guaranteed, since floating point formats cannot always represent a number exactly.
EXAMPLE
!temp Real,,r8
!temp Int,,i4
tmp.Real = 5.6
sys.Rounding = ON
tmp.Int = tmp.Real /* tmp.Int is 6 */
sys.Rounding = OFF
tmp.Int = tmp.Real /* tmp.Int is 5 */
RELATED TOPICS |