Liquid divided_by and ceil filter return wrong value

Solved

Liquid divided_by and ceil filter return wrong value

mdarifulislam
Shopify Partner
4 0 1

 

{% assign max_avail_columns = 3 | divided_by: 5 | ceil %} code return 0 value with ceil formatter, it should return 1. I think this is a bug in Liquid. It should (3/5=0.6) and ceil(0.6)=1 but return 0 

 

 

Screenshot at Jun 04 22-47-12.png

Screenshot at Jun 04 22-52-28.png

Accepted Solution (1)

DrewOswald
Shopify Partner
81 18 24

This is an accepted solution.

It’s not a bug — it’s just how Liquid handles numbers. When you write 3 | divided_by: 5, Liquid does integer math, so the result is 0. Then 0 | ceil is still 0.

 

To fix it, make one of the numbers a decimal:

{% assign max_avail_columns = 3.0 | divided_by: 5 | ceil %}

 

Now it does 3.0 ÷ 5 = 0.6, and ceil turns that into 1.

 

DrewOswald_0-1749059348487.png

 

devDrew webDev · Need a developer? Send me a DM.
Follow me on Instagram for Shopify Tips & Tricks: https://www.instagram.com/devdrew.webdev/

View solution in original post

Replies 2 (2)

DrewOswald
Shopify Partner
81 18 24

This is an accepted solution.

It’s not a bug — it’s just how Liquid handles numbers. When you write 3 | divided_by: 5, Liquid does integer math, so the result is 0. Then 0 | ceil is still 0.

 

To fix it, make one of the numbers a decimal:

{% assign max_avail_columns = 3.0 | divided_by: 5 | ceil %}

 

Now it does 3.0 ÷ 5 = 0.6, and ceil turns that into 1.

 

DrewOswald_0-1749059348487.png

 

devDrew webDev · Need a developer? Send me a DM.
Follow me on Instagram for Shopify Tips & Tricks: https://www.instagram.com/devdrew.webdev/
mdarifulislam
Shopify Partner
4 0 1

Thank you, DrewOswald i found the solution based on your reply, that is {% assign max_avail_columns = 3.0 | plus:0.0 | divided_by: 5 | ceil %} its gives the correct value 👍