For the complete documentation index, see llms.txt. This page is also available as Markdown.

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.

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

Syntax

{{ 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:

{% 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:

Output:

Compare a metafield value numerically:

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

Last updated