Liquid divided_by and ceil filter return wrong value

Topic summary

A user encountered unexpected behavior when using Liquid’s divided_by and ceil filters together. The code 3 | divided_by: 5 | ceil returned 0 instead of the expected 1.

Root cause: Liquid performs integer division by default when both operands are integers. This means 3 | divided_by: 5 evaluates to 0 (not 0.6), and ceil of 0 remains 0.

Solution: Convert at least one operand to a decimal to enable float division:

  • 3.0 | divided_by: 5 | ceil correctly returns 1
  • Alternative: 3.0 | plus: 0.0 | divided_by: 5 | ceil

The issue is resolved. This is expected Liquid behavior rather than a bug—integer math requires explicit decimal notation for float operations.

Summarized with AI on October 27. AI used: claude-sonnet-4-5-20250929.

{% 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

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.

1 Like

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 :+1:

1 Like