Skip to content

Arithmetic Utilities

AstraDoc provides several utility functions that allow simple arithmetic operations on data, the result of which will be outputted during document render. Values provided to arithmetic functions can be either literal number values or properties referenced from the JSON payload.

The 4 basic arithmetic operators: addition, subtraction, multiplication and division are available for use through their associated utility function.

Sums the provided values together and outputs the result.

sum val1 val2 val3...
{{sum 25 10.5 age}}

The example above will sum the numbers 25, 10.5 and the value of the JSON property age together.

Subtracts the provided values from each other and outputs the result.

sub val1 val2 val3...
{{sub totals.income totals.expenses}}

Multiplies the provided values with each other and outputs the result.

mul val1 val2 val3...
{{mul price 0.15}}

Divides the provided values by each other and outputs the result.

div val1 val2 val3...
{{div percentage 100}}

The various arithmetic operations can be combined within a single statement to allow complex expressions to be computed at once.

{{mul price (div (sum markup_perc comm_perc) 100)}}

The expression above will compute the final markup on the price for the sale of an item. It will do this by multiplying the price JSON property by the total markup percentage. The total markup percentage is obtained by summing the markup percentage (markup_perc) and commission percentage (comm_perc) JSON properties together and dividing the result of that operation by the literal value 100.

The example above may be better understood when written out as a normal algebraic expression:

price * ((markup_perc + comm_perc) / 100)