Why if statement in Shopify-Liquid is not working as expected?
Why if statement in Shopify-Liquid is not working as expected?
I'm working with array of array in shopify-liquid and when i am trying to use the if statement to get only records where charge[2] > 0 but somehow its including the records where charge[2] = 0 and i'm not able to understand why is it happening.
{% assign array_of_arrays = [["0.0","5.0","0.0"],["0.0","6.6","8.8"],["0.0","9.9","1.1"]] %}
{%- for header in array_of_arrays -%}
{%- for charge in header[-1] -%}
{% if charge[2] > 0 %}
"this is it!!"
{% endif%}
{%- endfor -%}
{%- endfor -%}
Can anyone please help me understand where i'm making the mistake?
I found a way to get this sorted by using a small trick. Before, if sattement i convereted the string to a float and hence it worked.
{%- for header in array_of_arrays -%}
{%- for charge in header[-1] -%}
{%- assign char_2 = charge[2] | replace: ',' '.' | string.to_float -%}
{% if char_2 > 0 %}
charge: {{}} {{charge}} {{}}
{% endif%}
{%- endfor -%}
{%- endfor -%}
I hope it helps.
December 30, 2023
Turbo Multi-language Translator
Make the better internet purchasing globaly
Turbosify SEO Speed Booster
5.0 (7)•Free plan available
Get better conversions by improving store loading speed
Installed
Turbo Multi-language Chat - AI Customer service in one hand
December 30, 2023