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
Hey Community! As we jump into 2025, we want to give a big shout-out to all of you wh...
By JasonH Jan 7, 2025Hey Community! As the holiday season unfolds, we want to extend heartfelt thanks to a...
By JasonH Dec 6, 2024Dropshipping, a high-growth, $226 billion-dollar industry, remains a highly dynamic bus...
By JasonH Nov 27, 2024