Permalink
Browse files

tweaked previous merge

  • Loading branch information...
1 parent a9c53bc commit 88de457774f827b1d36880eaf13cd9e1de13e980 @fabpot committed Dec 28, 2011
Showing with 16 additions and 10 deletions.
  1. +4 −0 CHANGELOG
  2. +2 −3 doc/filters/number_format.rst
  3. +10 −7 lib/Twig/Extension/Core.php
View
@@ -1,3 +1,7 @@
+* 1.5.0-RC2
+
+ * added a number_format filter
+
* 1.5.0-RC1 (2011-12-26)
* removed the need to quote hash keys
@@ -1,8 +1,8 @@
``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:
@@ -36,4 +36,3 @@ The defaults set for ``number_format`` can be over-ridden upon each call using t
additional parameters.
.. _`number_format`: http://php.net/number_format
-
@@ -93,10 +93,10 @@ public function getFilters()
{
$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'),
@@ -352,15 +352,18 @@ function twig_date_format_filter(Twig_Environment $env, $date, $format = null, $
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);
}

0 comments on commit 88de457

Please sign in to comment.