How to use sprintf in Twig to format a number?

后端 未结 2 1330
心在旅途
心在旅途 2021-01-18 03:22

I need to format a number like this:

sprintf(\"%05d\",$lineNumber)

But I\'m inside a Symfony2 Twig template. So what can I do?

相关标签:
2条回答
  • 2021-01-18 03:55

    If i was 4 before, then after adding this to your Twig template:

    "%02d"|format(i)

    ...it will become 04.

    0 讨论(0)
  • 2021-01-18 04:00

    Twig provides lots of filters, take a look at format and number_format.

    0 讨论(0)
提交回复
热议问题