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 }}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 fallbackPrecision is a separate concern — chain
round: 2for a number, or useto_fixed: 2for a fixed-decimal string ("12.50")JavaScript has a single number type, so a trailing zero cannot survive as a number:
"12.50" | decimalis12.5. If a partner API needs12.50it must be sent as a stringSee also:
integer,to_fixed,round,is_number
Last updated