Home > Shopify Development > Liquid abs: Show absolute value of a number

How to show absolute value of a number in Shopify

Sam Nguyen
Sam Updated: July 16, 2024


Drive 20-40% of your revenue with Avada
avada email marketing

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.

Sam Nguyen is the CEO and founder of Avada Commerce, an e-commerce solution provider headquartered in Singapore. He is an expert on the Shopify e-commerce platform for online stores and retail point-of-sale systems. Sam loves talking about e-commerce and he aims to help over a million online businesses grow and thrive.

Stay in the know

Get special offers on the latest news from AVADA.