From e3b81ad8cd68179cc742399eedebde82d4a85862 Mon Sep 17 00:00:00 2001 From: Mark Story Date: Wed, 28 Dec 2011 11:13:27 -0500 Subject: [PATCH] Add documentation page for number_format. --- doc/filters/index.rst | 1 + doc/filters/number_format.rst | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 0 deletions(-) create mode 100644 doc/filters/number_format.rst diff --git a/doc/filters/index.rst b/doc/filters/index.rst index 6593a06..6a967b5 100644 --- a/doc/filters/index.rst +++ b/doc/filters/index.rst @@ -7,6 +7,7 @@ Filters date format replace + number_format url_encode json_encode convert_encoding diff --git a/doc/filters/number_format.rst b/doc/filters/number_format.rst new file mode 100644 index 0000000..8b5f90b --- /dev/null +++ b/doc/filters/number_format.rst @@ -0,0 +1,39 @@ +``number_format`` +================= + +.. versionadded:: 1.6 + The number_format filter was added in Twig 1.6 + +The ``number_format`` filter formats numbers. It is a wrapper around PHP's +`number_format`_ function: + +.. code-block:: jinja + + {{ 200.35|number_format }} + +You can control the number of decimal places, decimal point, and thousands +separator using the additional arguments: + +.. code-block:: jinja + + {{ 9800.333|number_format(2, ',', '.') }} + +If no formatting options are provided then Twig will use the default formatting +options of: + +- 0 decimal places. +- ``.`` as the decimal point. +- ``,`` as the thousands separator. + +These defaults can be easily changed through the core extension: + +.. code-block:: php + + $twig = new Twig_Environment($loader); + $twig->getExtension('core')->setNumberFormat(3, ',', '.'); + +The defaults set for ``number_format`` can be over-ridden upon each call using the +additional parameters. + +.. _`number_format`: http://php.net/number_format + -- 1.7.2.5