Introduction | Language Structure | IB Statements | File System | Comet 32 Runtime | Index |
| Syntax: | ROUND [numeric-variable-list] |
| Discussion: |
The ROUND statement defines numeric variables to be rounded
rather than truncated.
The numeric-variable-list includes the names of the previously-defined numeric variables that are to be rounded. The numeric-variable-list is optional. If it is not included, all numeric variable definitions following the ROUND statement will be rounded. Rounding or truncating occurs when the precision of the result of a numeric operation or expression exceeds the defined precision of a receiving numeric variable. If the digit following the right-most defined digit is greater than or equal to 5, the number is rounded up; otherwise the extra digits are truncated. Also see LENGTH. |
| Example 1: |
LENGTH 8.2 LOCAL VALUE1, VALUE2 ROUND VALUE1In this example, two numeric variables are defined with a length and precision of 8.2. However, just the first one (VALUE1) is specified for rounding. Any operation which produces a value to be stored in VALUE1 will round the value to the second decimal place. A similar operation with VALUE2 will truncate (not round) the data past the second decimal place. |
| Example 2: |
ROUND LENGTH 8.2 LOCAL VALUE1, VALUE2 LENGTH 5.3 COMMON DATA1, DATA2Here, the ROUND statement appears before the definitions of the data variables. This means that all the numeric variables following the ROUND statement will be rounded. |
| Example 3: |
LENGTH 8.2 LOCAL VALUE(50) ROUND VALUEIn this example, the ROUND statement is applied to an array called VALUE (which contains 50 elements, all with a length and precision of 8.2). The ROUND statement will affect all elements in the array (i.e., they will all be rounded). |