# Controlling rounding in numeric expressions

ACL uses fixed-point arithmetic for its numeric operations, with the exception of financial functions, for two reasons:

• It improves processing speed

• It allows user control over decimal numbers and rounding

By default, in calculations that involve two or more values, ACL rounds to the larger number of decimals of the first two operands. This rule is applied at each level in any calculation, starting at the lowest level, and repeated until the expression is evaluated. Rounding is the most common cause of numeric errors in ACL.

Note

You can use the SET MATH command to change the number of decimal places that result from a mathematical operation.

## Rounding in division

Rounding occurs more commonly in division than in multiplication. ACL rounds to the largest number of decimals from the operands. For example:

`7/3 = 2`

The correct answer is 2.333333333..., but ACL rounds this to zero decimals since neither operand has any decimals. Further examples are:

`7/3.00 = 2.33`
`7.0000/3.000 = 2.3333`

## Rounding in multiplication

ACL rounds to the largest number of decimals from the operands. For example:

`1.1 * 1.1 = 1.2`

Whereas

`1.10 * 1.1 = 1.21`

To control rounding, multiply your calculation by 1, including the number of decimal places that you want in your result. For example, specify 1.00 to ensure that there are at least two decimal places in the result.

In the following example, ACL rounds the result to two decimals:

`7.21 * 2.33 = 16.80`

To control the number of decimals to achieve a more accurate result, do the following:

`1.0000 * 7.21 * 2.33 = 16.7993`

Specifying the order of operations

Placement of parentheses plays an important role in determining the level of precision obtained in the calculation. Be careful when using parentheses to override the normal order of operations.

An example of how ACL processes an expression that includes division, multiplication, and parentheses involves calculating one day’s interest on \$100,000 at 12%:

`100000 * (0.12/365)`

ACL first divides 0.12 by 365 (giving 0.00), and then multiplies this result by100000 to yield 0.00. The correct answer is 32.876712..., but since the example uses parentheses to force ACL to evaluate the interest rate first, the result is rounded to zero.

If the parentheses are removed, the answer is correct to the penny:

`100000 * 0.12/365 = 32.88`