Performing calculations

Simple calculations are simple to perform. The arithmetic operators are the normal ones, except for division:
+, -, * (multiplication) and div (division).
Some examples would be:

You owe me «FormatNumber(Debt)». Pay within 5 days and I will give you a 10% discount – i.e. you will only need to pay «FormatNumber(Debt * 0.9)».

A more formal way of calculating the amount less 10% would be «Amount – (Amount * 10) div 100».

One thing to be careful of is to make sure that the arithmetic operators have at least one space on either side of them. Try it and see what happens if you leave out the spaces (particularly around a minus sign – subtraction).

Suppose we have a template producing an invoice, or statement. The data could be located in a data source, or be captured by the user. It makes no difference where the data come from, the template and commands will be the same. Here’s a snippet:




Unit cost


Total inc. Tax

«ForEach(Transaction)»«Product» «Qty» «UnitCost» «UnitCost * Qty» «FormatNumber(UnitCost * Qty * 1.14)»«End(foreach)»



More information is given in the recipe Using variables. Specifically, this recipe will show how you can add a column of amounts in a table.