is_number
Tests whether a value can be cast to a number, without casting it. The guard that pairs with integer and decimal.
{% if row.qty | is_number %}...{% endif %}Syntax
{{ value | is_number }}Parameter
Description
value
Any value to test
Return Value
Returns true when integer/decimal would succeed on the value, false otherwise.
Examples
Report bad rows instead of importing them silently:
{% for row in rows %}
{% unless row.price | is_number %}
{% assign invalid = invalid | push: row.sku %}
{% continue %}
{% endunless %}
{% assign price = row.price | decimal %}
{% endfor %}
{% if invalid.size > 0 %}
{% log "Rows skipped, price is not numeric: " | append: invalid | join: ", " %}
{% endif %}Branch on the shape of an incoming value:
Notes
Uses exactly the same rule as
integeranddecimal, so atrueresult guarantees the cast returns a number rather than the fallback"0x1F","1e3","1,234","",trueand missing variables are allfalseTo inspect the underlying JavaScript type instead, use
typeSee also:
integer,decimal,type
Last updated