Number Filters¶
A couple of filters for formatting numbers are included.
The formatting of numbers is based on the locale set on the template in Lime Admin, which affects things such as the separator between thousands and decimals. The locale can be overridden per filter call (see below).
Formatting¶
- All number format filters have
localeas an optional parameter which will override the template locale set in Lime Admin. Examples below are from a template with the (default) locale set to Swedish (Sweden).
Number¶
Standard number formatter.
format_number(
locale=default_locale,
decimal_places=None
)
Options¶
locale: The locale used to format the number. Defaults to the template locale.decimal_places: Formats to the given number of decimal place, rounds if the number is less than available decimals. Displays all decimals if None. Defaults to None.
Examples¶
Example with 12345678.011231:
{{ deal.totalvalue | format_number }}
12 345 678,011231
{{ deal.totalvalue | format_number(locale="en_US") }} (force US English)
12,345,678.011231
{{ deal.totalvalue | format_number(locale="da_DK") }} (force Danish)
12.345.678,011231
{{ deal.totalvalue | format_number(locale="da_DK", decimal_places=2) }} (force Danish, display 2 decimal places)
12.345.678,01
Example with 129.78:
{{ deal.totalvalue | format_number }}
129,78
{{ deal.totalvalue | format_number(decimal_places=1) }} (display 1 decimal place)
129,8
{{ deal.totalvalue | format_number(decimal_places=3) }} (display 3 decimal places)
129,780
Percent¶
Standard percent formatter.
format_percent(
locale=default_locale
)
Options¶
locale: The locale used to format the number. Defaults to the template locale.
Examples¶
Example with .752:
{{ deal.probability | format_percent }}
75 %
{{ deal.probability | format_percent(locale="en_US") }} (force US English)
75%
Custom pattern¶
Format a number using a custom pattern.
format_number_pattern(
pattern,
locale=default_locale,
strict_decimal_formatting=True
)
Options¶
pattern: A Locale Data Markup Language specification (LDML) pattern.locale: The locale used to format the number. Defaults to the template locale.strict_decimal_formatting: Should decimals be rounded and truncated to match the given pattern? If False, all decimals will be rendered regardless of the pattern. Defaults to True.
Examples¶
Example with 12345678.011231:
{{ deal.totalvalue | format_number_pattern('###,##0.##') }}
12 345 678,01
{{ deal.totalvalue | format_number_pattern('###,##0.##', locale="en_US") }} (force US English)
12,345,678.01
{{ deal.totalvalue | format_number_pattern('###,##0.##', locale="da_DK") }} (force Danish)
12.345.678,01
{{ deal.totalvalue | format_number_pattern('###,##0.##', locale="da_DK", strict_decimal_formatting=False) }} (force Danish, unrestrict decimals)
12.345.678,011231
# For the example, assume deal.totalvalue is 0.01015
{{ deal.totalvalue | format_number_pattern('##,##0.##%', locale="en_US") }} (force US English, render percent restrict to two decimals)
1.02%