How to show absolute value of a number in Shopify

Since 2006, Liquid has been used in Shopify as a language template. In Liquid, you use tags consisting of comment, control flow, iteration, raw, and variable to show complex content. In today tutorial, we will tell you about math filters, especially abs value so that you are able to display math formulas.

Table of content

General information about Liquid

Liquid is the backbone language of Shopify and has been trusted by a lot of web developers. Liquid is one of the Shopify’s open-source template languages. The template has been sold since 2006 and now become a good source for a lot of hosted website application such as Jekyll, salesforce desk, and zendesk.

What is math filter

Math filters let you apply mathematical tasks. Math filters can be linked, and like other filters in Liquid, the computer will read math filter from left to right. In the example below, the computer will access minus then times and finally divided by.

You save {{ product.compare_at_price | minus: product.price | times: 100.0 | divided_by: product.compare_at_price }}%

How to show absolute value of a number

Math filters contain a lot of types, and this tutorial focuses on abs. Abs returns the absolute value of a number. You have already known about the absolute number when studying about math in high school, right? For instance, abs will generate a positive number.


{{ -17 | abs }}



In addition, abs also work on a string if the string only contains a number.


{{ "-19.86" | abs }}




To sum up, math filters help to apply mathematics formulas on your website. Abs is a value that produces positive number which is familiar with absolute number that you have known in your high school. We hope that you find this useful and let us know about your difficulties.

Recommend for you
Image Description
SEO Suite [FREE]

Auto-optimize website elements and structure in one-click.

Learn more
Proofo - Social Proof [FREE]

Use Social proof to boost sales

Learn more
Image Description
Size Chart [FREE]

Stunning size guide for great shopping experience

Learn more
Image Description
Free Shipping Bar [FREE]

Increase customers’ shopping cart size with free shipping offer

Learn more

Comments for Liquid abs: Show absolute value of a number


Stay in the know

Get special offers on the latest news from AVADA.

40k subscribers has been joined!

Earn $10 in reward now!

go up