# calc

Let's you perform calculations with b@se tags

## Example

``````[%calc [@grand_total@] - [@sub_total@] + 10 * 2 /%]
``````

#### Add to the existing value in a variable

Add to an existing value in a variable:

``````[%set [@price@] %]20[%/set%]
[%calc [@price@] += 10 /%]
``````

Result: `30`

#### Assign a value to a variable

You can assign a value to a variable:

``````[%calc [@price@] = 20 /%]
``````

`[@price@]` now has the value of `20`.

#### Remainder

When using division, only display the remainder:

``````[%calc 45%7 /%]
``````

Result: `3`

#### Power (exponents)

Eight to the fifth power:

``````[%calc 8**5 /%]
``````

Result: `32768`

## Usage

The calc tag lets you perform arithmetic on base tags and static integers for a variety of results.

You can perform calculations between static values, base tags, results from formatting with any of the operators below.

This can also be combined with the `set` tag for more advanced calculations.

#### Order of Calculation

The calc function follows that standard rules for calculation. Multiplication and division are completed first, followed by addition and subtraction. So the calculation:

``````[%calc 2 + 8 / 5 /%]
``````

Returns `3.6` since `8 / 5` is calculated first. Use the brackets to force a calculation to be done before another:

``````[%calc (2 + 8) / 5 /%]
``````

This will return `2`.

## Parameters

Name Description
`*` Multiply
`/` Divide
`+` Add
`+=` Add to the existing value in a variable
`-` Subtract
`=` Assign a value to a variable
`%` Remainder
`**` Power
`( )` Brackets to specify the order of operations