> For the complete documentation index, see [llms.txt](https://docs.datajet-app.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.datajet-app.com/liquid/filters/decimal.md).

# decimal

Casts a value to a number, keeping the fractional part. The decimal counterpart of `integer` — use it for prices, weights and rates that arrive as strings.

```liquid
{% assign price = row.price | decimal: 0 %}
```

## Syntax

```liquid
{{ value | decimal }}
{{ value | decimal: fallback }}
```

| Parameter  | Description                                                          |
| ---------- | -------------------------------------------------------------------- |
| `value`    | The value to cast. Numbers and decimal strings are accepted          |
| `fallback` | Optional. Returned when the value is not a number. Defaults to `nil` |

## Return Value

Returns a number, or the fallback (`nil` by default) when the value cannot be cast.

## Examples

**Sum a price column from a CSV:**

```liquid
{% assign rows = file.content | parse_csv %}
{% assign total = 0 %}
{% for row in rows %}
  {% assign total = total | plus: row.price | decimal: 0 %}
{% endfor %}
{% log "Order total: " | append: total %}
```

**Round to a fixed precision:**

```liquid
{% assign price = "12.567" | decimal | round: 2 %}
{{ price }}
```

Output:

```
12.57
```

**Compare a metafield value numerically:**

```liquid
{% assign weight = product.metafield.value | decimal: 0 %}
{% if weight > 20 %}
  {% assign shipping = "freight" %}
{% endif %}
```

## Notes

* Same strict parsing as `integer`: hex (`"0x1F"`), exponent notation (`"1e3"`), thousands separators (`"1,234"`), booleans and empty strings all return the fallback
* Precision is a separate concern — chain `round: 2` for a number, or use `to_fixed: 2` for a fixed-decimal **string** (`"12.50"`)
* JavaScript has a single number type, so a trailing zero cannot survive as a number: `"12.50" | decimal` is `12.5`. If a partner API needs `12.50` it must be sent as a string
* See also: `integer`, `to_fixed`, `round`, `is_number`
