Search code examples
twignumber-formatting

Twig - 'number_format' returns zero


I was playing with 'number_format' filter to see if I can get a value 'M' from a version string 'M.m.p'.

In this online playground, it looks it works:

{% set lastVersion = "15.4.6" | number_format %}

{{ lastVersion }}

Output: 15

But inside my project, I try the same, but I get '0' as output.

I tried to update gulp twig but it didn't work. What is missing here? And there is an alternative?


Solution

  • You could use the following snippet

    {{ ("15.5.4" | split('.'))[0] }}