twigintltwig-extension

localizedcurrency filter raise 'non well formed numeric value' after division


I'm using Twig for render a template that contains something like this:

{{ any_int_number / 100.0|localizedcurrency('EUR') }} 

That localizedcurrency filter comes from Twig_Extensions_Extension_Intl and allows to convert a number in the right format based on the locale currently set.

If I leave that /100.0 division there, I'm getting the following error:

 A non well formed numeric value encountered in /****/vendor/twig/twig/src/Environment.php(418) : eval()'d code on line 136

Now, if I do something like this, it will work perfectly:

{{ 3.99 |localizedcurrency('EUR') }} 

It's hard to figure out which type is returned after that division and why this error occurs, it looks like an issue, any help ?


Solution

  • Filters have a higher precedence than mathematical calculations in twig. You should add parentheses

    {{ (any_int_number / 100.0)|localizedcurrency('EUR') }}