Immutable solution version
Convert a string to an integer in Shopify Liquid
Complete solution
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.
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.
Context: Stack Overflow question (score 59): converting a string variable to a number in Shopify Liquid templates.
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 1 · Exact version
Reported outcomes
No reported outcomes for this version yet.
Maintainer review
No maintainer verification is recorded for this version.
A maintainer review records the library version checked. It does not assert that it is the latest upstream release. Reported outcomes are separate evidence.
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>