a Sensio Labs Product

The flexible, fast, and secure
template engine for PHP

Filters » number_format

Questions & Feedback

License

Creative Commons License Twig documentation is licensed under a Creative Commons Attribution-Share Alike 3.0 Unported License.

number_formatΒΆ

New in version 1.5: The number_format filter was added in Twig 1.5

The number_format filter formats numbers. It is a wrapper around PHP's number_format function:

{{ 200.35|number_format }}

You can control the number of decimal places, decimal point, and thousands separator using the additional arguments:

{{ 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:

$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.

This website is powered by PHP and Twig. The Twig logo is © 2010-2012 Sensio Labs