Using Parentheses in Calculations

Illume calculations use parentheses to determine which parts of a calculation should be evaluated first. If the calculation uses only addition and subtraction, parentheses do not matter. If the calculation uses multiplication or division, parentheses matter very much.

Illume will scan a calculation from right to left, evaluating all expressions in parentheses, followed by all multiplication operations, then all division operations, then all addition operations, and finally all subtraction operations.

Note the following examples:

  • ({Value:SALARY} + {Value:BONUS} + {Value:OTHERINCOME})
    • This calculation simply adds together a participant’s salary, bonus, and other income.
  • ({Value:SALARY} + {Value:BONUS} * {Value:TAXRATE})
    • This would be an incorrect calculation for the amount of income tax a person pays. If salary is 40000 and bonus is 2000 and tax rate is 0.28, this calculation will produce the following result:

40000 + (2000 * 0.28) = 40000 + 560 = 40560

The correct calculation uses parentheses to add salary and bonus before applying the tax rate.

(({Value:SALARY} + {Value:BONUS}) * {Value:TAXRATE})

Which works out as follows:

(40000 + 2000) * 0.28 = 42000 * 0.28 = 11760