Skip to main content

Number Filters

Filters for formatting and manipulating numeric values.

Formatting

FilterArgumentsDescription
number_formatdecimals, dec_point, thousands_sepFormat number
number_i18ndecimalsFormat using WordPress localization

number_format Arguments:

  • decimals — Decimal places (default: 0)
  • dec_point — Decimal separator (default: '.')
  • thousands_sep — Thousands separator (default: ',')
{{ 1234|number_format }}                       <!-- 1,234 -->
{{ 1234.5|number_format(2) }} <!-- 1,234.50 -->
{{ 1234.5|number_format(2, ',', ' ') }} <!-- 1 234,50 -->
{{ 1234.5|number_format(2, '.', ',') }} <!-- 1,234.50 -->

number_i18n Arguments:

  • decimals — Decimal places (default: 0)

Uses WordPress number_format_i18n() for locale-aware formatting.

{{ 1234|number_i18n }}
{{ 1234.567|number_i18n(2) }}

Rounding

FilterArgumentsDescription
roundprecision, methodRound number
absAbsolute 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_i18n }}