Skip to content

Commit

Permalink
bug #3626 The deprecated null value for the method round has been cha…
Browse files Browse the repository at this point in the history
…nged to zero. (v.arsentev)

This PR was submitted for the 3.x branch but it was squashed and merged into the 2.x branch instead.

Discussion
----------

The deprecated null value for the method round has been changed to zero.

Commits
-------

7d0e5d6 The deprecated null value for the method round has been changed to zero.
  • Loading branch information
fabpot committed Jan 11, 2022
2 parents 4c225d5 + 7d0e5d6 commit e8068a9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Extension/CoreExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,8 @@ function twig_replace_filter($str, $from)
*/
function twig_round($value, $precision = 0, $method = 'common')
{
$value = (float) $value;

if ('common' === $method) {
return round($value, $precision);
}
Expand All @@ -589,8 +591,6 @@ function twig_round($value, $precision = 0, $method = 'common')
throw new RuntimeError('The round filter only supports the "common", "ceil", and "floor" methods.');
}

$value = (float) $value;

return $method($value * 10 ** $precision) / 10 ** $precision;
}

Expand Down
4 changes: 4 additions & 0 deletions tests/Fixtures/filters/round.test
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

{{ ''|round(-1, 'floor')}}
{{ null|round(-1, 'floor')}}
{{ null|round }}
{{ null|round(2, 'ceil') }}
--DATA--
return []
--EXPECT--
Expand All @@ -28,3 +30,5 @@ return []

0
0
0
0

0 comments on commit e8068a9

Please sign in to comment.