Skip to content

ceil

The ceil filter rounds a numeric value up to the nearest integer. This means it always returns the smallest integer greater than or equal to the input value.

Functionality

  • Numbers: Takes a numerical value as input (integer or floating-point).
  • Rounding Up: Rounds the input number towards positive infinity, to the next whole number.
  • Output: Returns a new integer value representing the rounded result.

Syntax

    {{ input_number | ceil }}
Arguments

The ceil filter does not require any arguments.

Code Samples

Example 1: Rounding Up a Decimal

    {% assign price = 12.34 %}

    {{ price | ceil }}
Output:
13
Example 2: No Change for Integers

    {% assign quantity = 5 %}
    {{ quantity | ceil }}
Output:
5
Example 3: Rounding Up a Negative Decimal

    {% assign temperature = -7.8 %}
    {{ temperature | ceil }}
Output:
-7

Outliers and Special Cases

  • Non-Numeric Input: If the input is not a number (e.g., a string or boolean), the ceil filter might attempt to convert it to a number before rounding. If the conversion fails, an error might be thrown.

Key Points

  • The ceil filter is a fundamental mathematical tool for rounding numbers within templates.
  • It is particularly useful when you want to ensure that a value is not lower than a certain integer threshold.
  • Use cases include calculating minimum quantities, determining the number of pages for content, or any situation where you need to round a fractional value up to the nearest whole number.
  • Be mindful of data types to ensure correct behavior and avoid errors.