1``format_currency``
2===================
3
4.. versionadded:: 2.12
5
6    The ``format_currency`` filter was added in Twig 2.12.
7
8The ``format_currency`` filter formats a number as a currency:
9
10.. code-block:: twig
11
12    {# €1,000,000.00 #}
13    {{ '1000000'|format_currency('EUR') }}
14
15You can pass attributes to tweak the output:
16
17.. code-block:: twig
18
19    {# €12.34 #}
20    {{ '12.345'|format_currency('EUR', {rounding_mode: 'floor'}) }}
21
22    {# €1,000,000.0000 #}
23    {{ '1000000'|format_currency('EUR', {fraction_digit: 4}) }}
24
25The list of supported options:
26
27* ``grouping_used``;
28* ``decimal_always_shown``;
29* ``max_integer_digit``;
30* ``min_integer_digit``;
31* ``integer_digit``;
32* ``max_fraction_digit``;
33* ``min_fraction_digit``;
34* ``fraction_digit``;
35* ``multiplier``;
36* ``grouping_size``;
37* ``rounding_mode``;
38* ``rounding_increment``;
39* ``format_width``;
40* ``padding_position``;
41* ``secondary_grouping_size``;
42* ``significant_digits_used``;
43* ``min_significant_digits_used``;
44* ``max_significant_digits_used``;
45* ``lenient_parse``.
46
47By default, the filter uses the current locale. You can pass it explicitly:
48
49.. code-block:: twig
50
51    {# 1.000.000,00 € #}
52    {{ '1000000'|format_currency('EUR', locale='de') }}
53
54.. note::
55
56    The ``format_currency`` filter is part of the ``IntlExtension`` which is not
57    installed by default. Install it first:
58
59    .. code-block:: bash
60
61        $ composer require twig/intl-extra
62
63    Then, on Symfony projects, install the ``twig/extra-bundle``:
64
65    .. code-block:: bash
66
67        $ composer require twig/extra-bundle
68
69    Otherwise, add the extension explicitly on the Twig environment::
70
71        use Twig\Extra\Intl\IntlExtension;
72
73        $twig = new \Twig\Environment(...);
74        $twig->addExtension(new IntlExtension());
75
76Arguments
77---------
78
79* ``currency``: The currency
80* ``attrs``: A map of attributes
81* ``locale``: The locale
82