Skip to main content Link Search Menu Expand Document (external link)

+ : Addition Operator


On this page

Summary

Adds two numeric values together. Or joins two string values together.

Syntax

{{operand1 + operand2}}

Operands

Position Type Description
Left Number First value to add
Right Number Second value to add

Returns

Type: Number (same type as operands, or promoted type)

The sum of the two operands.


Examples

Basic Addition

{{5 + 3}}
<!-- Output: 8 -->

With Variables

<p>Subtotal: ${{model.price}}</p>
<p>Tax: ${{model.tax}}</p>
<p>Total: ${{model.price + model.tax}}</p>

Data:

doc.Params["model"] = new {
    price = 99.99m,
    tax = 8.00m
};

Output:

<p>Subtotal: $99.99</p>
<p>Tax: $8.00</p>
<p>Total: $107.99</p>

Multiple Additions

<p>Total: {{model.base + model.shipping + model.tax}}</p>

With Formatting

<p>Grand Total: {{format(model.subtotal + model.tax, 'C2')}}</p>

In #each Loop

{{#each model.items}}
  <p>Item {{@index + 1}}: {{this.name}}</p>
{{/each}}

Precedence

Priority level in expression evaluation: 5 (after *, /, %)


Notes

  • Works with int, long, double, decimal types
  • Works with strings, if, and only if, the first value is a string (e.g. ‘item_’ + index() = ‘item_1`
  • Mixed types are automatically converted (e.g., int + double = double)
  • Left-to-right associativity: a + b + c = (a + b) + c
  • Use parentheses to control order: (a + b) * c

See Also