Number Filters
Filters for formatting and manipulating numeric values.
Formatting
| Filter | Arguments | Description |
|---|---|---|
number_format | decimals, dec_point, thousands_sep | Format number |
number_i18n | decimals | Format 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
| Filter | Arguments | Description |
|---|---|---|
round | precision, method | Round 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_i18n }}