5 The ``number_format`` filter was added in Twig 1.5
7 The ``number_format`` filter formats numbers. It is a wrapper around PHP's
8 `number_format`_ function:
12 {{ 200.35|number_format }}
14 You can control the number of decimal places, decimal point, and thousands
15 separator using the additional arguments:
19 {{ 9800.333|number_format(2, '.', ',') }}
21 To format negative numbers, wrap the number with parentheses (needed because of
22 Twig's :ref:`precedence of operators <twig-expressions>`:
26 {{ -9800.333|number_format(2, '.', ',') }} {# outputs : -9 #}
27 {{ (-9800.333)|number_format(2, '.', ',') }} {# outputs : -9.800,33 #}
29 If no formatting options are provided then Twig will use the default formatting
33 * ``.`` as the decimal point.
34 * ``,`` as the thousands separator.
36 These defaults can be easily changed through the core extension:
40 $twig = new Twig_Environment($loader);
41 $twig->getExtension('Twig_Extension_Core')->setNumberFormat(3, '.', ',');
44 $twig->getExtension('core')->setNumberFormat(3, '.', ',');
46 The defaults set for ``number_format`` can be over-ridden upon each call using the
47 additional parameters.
52 * ``decimal``: The number of decimal points to display
53 * ``decimal_point``: The character(s) to use for the decimal point
54 * ``thousand_sep``: The character(s) to use for the thousands separator
56 .. _`number_format`: http://php.net/number_format