Discuss and resolve questions on Liquid, JavaScript, themes, sales channels, and site speed enhancements.
Im trying to assign a variable that has been converted from a string but the result variable stays as a string
{% assign multi_qty = multi_qty_str | to_i %}
{% if multi_qty > 0 %}{% endif %}
The above throws an error "Liquid error: comparison of String with 0 failed"
The below works but is it possible to avoid type casting each time
{% assign multi_qty = multi_qty_str | to_i %}
{% if multi_qty | to_i > 0 %}{% endif %}
I've tried:
{% assign multi_qty = (multi_qty_str | to_i) %}
And:
{% assign multi_qty = multi_qty_str | to_i + 0%}
but still show the same error
Problem solved:
{% assign multi_qty = multi_qty_str | to_i | abs %}
works
Learn how to build powerful custom workflows in Shopify Flow with expert guidance from ...
By Jacqui May 7, 2025Did You Know? May is named after Maia, the Roman goddess of growth and flourishing! ...
By JasonH May 2, 2025Discover opportunities to improve SEO with new guidance available from Shopify’s growth...
By Jacqui May 1, 2025