Solved

# How to convert numbers into words using liquid coding?

Visitor
2 0 0

I want to show Numbers to Words.

Total Amount to Total Amount in words in liquid coding.

Give some code, where it will solve.

Accepted Solution (1)
Shopify Partner
897 101 159

This is an accepted solution.

@shapnobuz Do you want ti display only at product page level? You will also need to use javascript to achieve this if the prices are different at variant level and you need the prices in words on cart page too.

- Was my reply helpful? Click Like or Click Accept as Solution
To hire: email us at shopify@propero.in
checkout our app https://apps.shopify.com/picamaze
Replies 2 (2)
Shopify Partner
897 101 159

This is an accepted solution.

@shapnobuz Do you want ti display only at product page level? You will also need to use javascript to achieve this if the prices are different at variant level and you need the prices in words on cart page too.

- Was my reply helpful? Click Like or Click Accept as Solution
To hire: email us at shopify@propero.in
checkout our app https://apps.shopify.com/picamaze
Visitor
2 0 2

If someone wants it in Liquid for Order Printer template, this simple code will help.  The words is for amount upto 999.99.  The code can be extended, if there are more digits.

Please add the definition top of the template:

{% assign hwords = 'Zero,One,Two,Three,Four,Five,Six,Seven,Eight,Nine,Zero' | split: ',' %}
{% assign twords = 'Zero,Ten,Twenty,Thirty,Forty,Fifty,Sixty,Seventy,Eighty,Ninety' | split: ',' %}
{% assign digit = 'Zero,One,Two,Three,Four,Five,Six,Seven,Eight,Nine,Zero' | split: ',' %}
{% assign tdigit = 'Zero,Eleven,Twelve,Thirteen,Fourteen,Fifteen,Sixteen,Seventeen,Eighteen,Nineteen' | split: ',' %}
{% assign test = "300.25" %}  {% comment %}  remove lines for test {% endcomment %}

Place below code where your amount in words should appear.  Change the variable total1 to whatever your variable name in your template.

{% comment %} for 6 digits {% endcomment %}
{% assign total1 = test %} {% assign s = total1.size %} {% if s == 6 %}{% assign x1 = total1 | slice: 0 %}

{% assign x1 = x1 | plus: 0 %}{{ hwords[x1] }} Hundred {% assign x1 = total1 | slice: 1, 2 %} {% assign x1 = x1 | plus: 0 %} {% if x1 > 10 and x1 < 20 %} {% assign x1 = x1 | minus: 10 %} {{ tdigit[x1] }}
{% else %} {% assign x1 = total1 | slice: 1 %} {% assign x1 = x1 | plus: 0 %}{% if x1 != 0 %} {{ twords[x1] }} {% endif %}
{% assign x1 = total1 | slice: 2 %} {% assign x1 = x1 | plus: 0 %} {% if x1 != 0 %} {{ digit[x1] }}
{% endif %} {% endif %}

{% assign x1 = total1 | slice: 4, 2 %} {{ x1 }} {% assign x1 = x1 | plus: 0 %} {% if x1 > 10 and x1 < 20 %} {% assign x1 = x1 | minus: 10 %} and Cents {{ tdigit[x1] }}
{% else %} {% assign x1 = total1 | slice: 4 %} {% assign x1 = x1 | plus: 0 %} and Cents {% if x1 != 0 %} {{ twords[x1] }} {% endif %} {% assign x1 = total1 | slice: 5 %} {% assign x1 = x1 | plus: 0 %} {% if x1 != 0 %}{{ digit[x1] }} {% endif %} {% endif %}
Only {% endif %}

{% comment %} for 5 digits {% endcomment %}
{% assign total1 = test %} {% assign s = total1.size %} {% if s == 5 %}{% assign x1 = total1 | slice: 0 %}

{% assign x1 = total1 | slice: 0, 2 %} {% assign x1 = x1 | plus: 0 %} {% if x1 > 10 and x1 < 20 %} {% assign x1 = x1 | minus: 10 %} {{ tdigit[x1] }}
{% else %} {% assign x1 = total1 | slice: 0 %} {% assign x1 = x1 | plus: 0 %}{% if x1 != 0 %} {{ twords[x1] }} {% endif %}
{% assign x1 = total1 | slice: 1 %} {% assign x1 = x1 | plus: 0 %} {% if x1 != 0 %} {{ digit[x1] }}
{% endif %} {% endif %}

{% assign x1 = total1 | slice: 3, 2 %} {{ x1 }} {% assign x1 = x1 | plus: 0 %} {% if x1 > 10 and x1 < 20 %} {% assign x1 = x1 | minus: 10 %} and Cents {{ tdigit[x1] }}
{% else %} {% assign x1 = total1 | slice: 3 %} {% assign x1 = x1 | plus: 0 %} and Cents {% if x1 != 0 %} {{ twords[x1] }} {% endif %} {% assign x1 = total1 | slice: 4 %} {% assign x1 = x1 | plus: 0 %} {% if x1 != 0 %}{{ digit[x1] }} {% endif %} {% endif %}
Only {% endif %}

{% comment %} for 4 digits {% endcomment %}
{% assign total1 = test %} {% assign s = total1.size %} {% if s == 4 %}

{% assign x1 = total1 | slice: 0 %} {% assign x1 = x1 | plus: 0 %}{% if x1 != 0 %} {{ digit[x1] }} {% endif %}

{% assign x1 = total1 | slice: 2, 2 %} {{ x1 }} {% assign x1 = x1 | plus: 0 %} {% if x1 > 10 and x1 < 20 %} {% assign x1 = x1 | minus: 10 %} and Cents {{ tdigits[x1] }}
{% else %} {% assign x1 = total1 | slice: 2 %} {% assign x1 = x1 | plus: 0 %} and Cents {% if x1 != 0 %} {{ twords[x1] }} {% endif %} {% assign x1 = total1 | slice: 3 %} {% assign x1 = x1 | plus: 0 %} {% if x1 != 0 %}{{ digit[x1] }} {% endif %} {% endif %}
Only {% endif %}

Hope this code helps someone who doesn't have large amounts.