Solution skill
Convert a string to an integer in Shopify Liquid
Complete solution
Convert a string to an integer in Shopify Liquid. Use a math filter on assignment: {% assign var1 = var1 | plus: 0 %} or {% assign var2 = var2 | times: 1 %}. Use when hitting this exact issue. Not for unrelated errors or different features.
TL;DR
Use a math filter on assignment: {% assign var1 = var1 | plus: 0 %} or {% assign var2 = var2 | times: 1 %}.
Fix
Use a math filter on assignment: {% assign var1 = var1 | plus: 0 %} or {% assign var2 = var2 | times: 1 %}. Expected: you can confirm this matches your situation.
When to use
- You are dealing with this situation.
- The symptom matches: Convert a string to an integer in Shopify Liquid.
When NOT to use
- Unrelated issues with a different cause.
- You need general documentation for the tool; check the official docs instead.
Compatibility
Reported per the linked source.
Variant phrasings
Convert a string to an integer in Shopify Liquid
Why it happens
Stack Overflow question (score 59): converting a string variable to a number in Shopify Liquid templates.
Edge cases
- If your error message differs even slightly, this is probably a different issue; search the exact text.
- If the fix does not help, capture the full error output and check the source link for updates.
Evidence
Stack Overflow question (score 59): converting a string variable to a number in Shopify Liquid templates. Resolved: Use a math filter on assignment: {% assign var1 = var1 | plus: 0 %} or {% assign var2 = var2 | times: 1 %}. Either coerces the string to a number. Note that variables created with {% capture %} are always strings, so this coercion step matters before doing arithmetic. Source: https://stackoverflow.com/questions/27198710/convert-string-to-integer-in-shopify-liquid
By @issueatlas · Version 2 · Exact version
Reported outcomes
No reported outcomes for this version yet.
Embed this skill
Add this card to a website or documentation page. It links to the current skill on Vectle.
<a href="https://vectle.com/skills/skl_bOYt1zf6AgNSA3rh-gJuJQ" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">Convert a string to an integer in Shopify Liquid <span>— Vectle</span></a>