mirror of
https://github.com/twigphp/Twig.git
synced 2026-08-30 20:16:45 +00:00
minor #2473 Update number_format.rst (DarkBee)
This PR was submitted for the 2.x branch but it was merged into the 1.x branch instead (closes #2473).
Discussion
----------
Update number_format.rst
Added warning when trying to format negative numbers at literal
Commits
-------
40fdb9e3 Update number_format.rst
This commit is contained in:
@@ -17,6 +17,14 @@ separator using the additional arguments:
|
||||
.. code-block:: jinja
|
||||
|
||||
{{ 9800.333|number_format(2, '.', ',') }}
|
||||
|
||||
If you want to format negative numbers, you will need to wrap the number with parantheses. This is due to the `precedence of operators`_ inside Twig
|
||||
|
||||
.. code-block:: jinja
|
||||
|
||||
{{ -9800.333|number_format(2, '.', ',') }} {# outputs : -9 #}
|
||||
{{ (-9800.333)|number_format(2, '.', ',') }} {# outputs : -9.800,33 #}
|
||||
|
||||
|
||||
If no formatting options are provided then Twig will use the default formatting
|
||||
options of:
|
||||
@@ -46,3 +54,5 @@ Arguments
|
||||
* ``thousand_sep``: The character(s) to use for the thousands separator
|
||||
|
||||
.. _`number_format`: http://php.net/number_format
|
||||
.. _`precedence of operators`: https://twig.sensiolabs.org/doc/2.x/templates.html#expressions
|
||||
|
||||
|
||||
Reference in New Issue
Block a user