# sum

Calculates the sum of all numeric values in an array. Non-numeric values are ignored.

```liquid
{% assign total = prices | sum %}
{% log total %}
```

#### Syntax

```liquid
{{ array | sum }}
```

| Parameter | Description            |
| --------- | ---------------------- |
| `array`   | Array of values to sum |

#### Return Value

Returns a number — the sum of all numeric values in the array. Non-numeric values are skipped.

#### Examples

**Sum order line item prices:**

```liquid
{% assign prices = order.line_items | map: "price" %}
{% assign total = prices | sum %}
{% log "Total: $" | append: total %}
```

**Sum quantities:**

```liquid
{% assign quantities = line_items | map: "quantity" %}
{% assign total_items = quantities | sum %}
{% log "Total items: " | append: total_items %}
```

**Sum values from a CSV import:**

```liquid
{% assign rows = file.content | parse_csv %}
{% assign amounts = rows | map: "amount" %}
{% assign total = amounts | sum %}
{% log "Import total: " | append: total %}
```

**Calculate total weight:**

```liquid
{% assign weights = order.line_items | map: "grams" %}
{% assign total_grams = weights | sum %}
{% assign total_kg = total_grams | divided_by: 1000.0 %}
{% log "Total weight: " | append: total_kg | append: " kg" %}
```

**Sum with mixed data (non-numeric values are ignored):**

```liquid
{% assign values = "10,abc,20,30,n/a" | split: "," %}
{% assign total = values | sum %}
{% log total %}
```

Output:

```
60
```

#### Notes

* Non-numeric values (strings, nulls, etc.) are silently skipped
* Values are parsed as floats, so decimal numbers are supported
* Combine with `map` to sum a specific property from an array of objects
* Returns `0` for an empty array
