``number_format``
=================
-.. versionadded:: 1.6
- The number_format filter was added in Twig 1.6
+.. versionadded:: 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:
additional parameters.
.. _`number_format`: http://php.net/number_format
-
{
$filters = array(
// formatting filters
- 'date' => new Twig_Filter_Function('twig_date_format_filter', array('needs_environment' => true)),
- 'format' => new Twig_Filter_Function('sprintf'),
- 'replace' => new Twig_Filter_Function('strtr'),
- 'number_format' => new Twig_Filter_Function('twig_number_format_filter', array('needs_environment' => true)),
+ 'date' => new Twig_Filter_Function('twig_date_format_filter', array('needs_environment' => true)),
+ 'format' => new Twig_Filter_Function('sprintf'),
+ 'replace' => new Twig_Filter_Function('strtr'),
+ 'number_format' => new Twig_Filter_Function('twig_number_format_filter', array('needs_environment' => true)),
// encoding
'url_encode' => new Twig_Filter_Function('twig_urlencode_filter'),
function twig_number_format_filter(Twig_Environment $env, $number, $decimal = null, $decimalPoint = null, $thousandSep = null)
{
$defaults = $env->getExtension('core')->getNumberFormat();
- if ($decimal === null) {
+ if (null === $decimal) {
$decimal = $defaults[0];
}
- if ($decimalPoint === null) {
+
+ if (null === $decimalPoint) {
$decimalPoint = $defaults[1];
}
- if ($thousandSep === null) {
+
+ if (null === $thousandSep) {
$thousandSep = $defaults[2];
}
+
return number_format((float) $number, $decimal, $decimalPoint, $thousandSep);
}