Skip to main content

Number Filters

Filters for formatting and manipulating numeric values.

Formatting​

FilterArgumentsDescription
number_formatdecimal, decimal_point, thousand_sepFormat number

number_format Arguments:

  • decimal — Decimal places (default: 0)
  • decimal_point — Decimal separator (default: the site's language, as in Timber)
  • thousand_sep — Thousands separator (default: the site's language, as in Timber)
{{ 1234|number_format }}                       <!-- 1,234 in English, 1 234 in French -->
{{ 1234.5|number_format(2) }} <!-- 1,234.50 in English, 1 234,50 in French -->
{{ 1234.5|number_format(2, ',', ' ') }} <!-- 1 234,50 -->
{{ 1234.5|number_format(2, '.', ',') }} <!-- 1,234.50 -->

Rounding​

FilterArgumentsDescription
roundprecision, methodRound number
abs—Absolute value

round Arguments:

  • precision — Decimal places (default: 0)
  • method — 'common' (default), 'ceil', or 'floor'
{{ 4.5|round }}                    <!-- 5 -->
{{ 4.567|round(1) }} <!-- 4.6 -->
{{ 4.567|round(2) }} <!-- 4.57 -->
{{ 4.5|round(0, 'ceil') }} <!-- 5 -->
{{ 4.5|round(0, 'floor') }} <!-- 4 -->
{{ 4.567|round(2, 'ceil') }} <!-- 4.57 -->
{{ -5|abs }} <!-- 5 -->

Common Patterns​

Format price​

${{ product.price|number_format(2) }}

Display rating​

{{ review.rating|round(1) }} out of 5

Format large numbers​

{{ view_count|number_format }}