Math Expressions
Math expressions let you compute a value inline and compare the result, without needing to pre-compute fields in your data.
Syntax
Section titled “Syntax”A math expression combines two operands with an arithmetic operator:
<operand> <operator> <operand> <comparison>Operands can be properties or literal numbers. Supported operators are +, -, *, and /.
Addition
Section titled “Addition”__subtotal__ of **Order** + __tax__ of **Order** is greater than 100Interactive Example
Policy Rule
Test Data (JSON)
Mix a property with a literal:
Interactive Example
Policy Rule
Test Data (JSON)
Subtraction
Section titled “Subtraction”__balance__ of **Account** - __pending__ of **Account** is at least 0Interactive Example
Policy Rule
Test Data (JSON)
Multiplication
Section titled “Multiplication”__quantity__ of **Order** * __unit_price__ of **Order** is greater than 1000Interactive Example
Policy Rule
Test Data (JSON)
Division
Section titled “Division”__revenue__ of **Store** / __expenses__ of **Store** is greater than 1.5Interactive Example
Policy Rule
Test Data (JSON)
Division by zero produces an evaluation error. Guard against it with an appropriate condition or ensure your data is valid before passing it to the engine.
Combining with Other Conditions
Section titled “Combining with Other Conditions”Math expressions can be combined with and and or like any other condition:
Interactive Example
Policy Rule
Test Data (JSON)
Summary
Section titled “Summary”| Operator | Example |
|---|---|
+ | __subtotal__ of **Order** + __tax__ of **Order** is greater than 50 |
- | __balance__ of **Account** - __reserved__ of **Account** is at least 0 |
* | __qty__ of **Order** * __price__ of **Order** is greater than 100 |
/ | __revenue__ of **Store** / __costs__ of **Store** is greater than 1 |
Both operands must be numeric. Using a non-numeric property in a math expression will produce a type error.