assign type casted string to int Liquid variables for packing slips

assign type casted string to int Liquid variables for packing slips

Ron585
Tourist
3 0 1

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

Reply 1 (1)

Ron585
Tourist
3 0 1

Problem solved:

 

{% assign multi_qty = multi_qty_str | to_i | abs %}

 

works