Skip to content

Commit

Permalink
The deprecated null value for the method round has been changed to zero.
Browse files Browse the repository at this point in the history
  • Loading branch information
v.arsentev authored and fabpot committed Jan 11, 2022
1 parent 4c225d5 commit 7d0e5d6
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 7d0e5d6

Please sign in to comment.