I want to round a value in Twig.
Example: I want to display 80.5555
as 80.55
.
Can any one suggest me how to do that?
{{ 80.5555 | number_format(2) }}
Here is the documentation number_format
You could use the format filter for that:
{{ '%.2f'|format(80.5555) }}
But note that it will round it to 80.56
.
Twig documentation says that there's a filter for this task, since 1.15.0:
just write {{80.5555|round}}
https://twig.symfony.com/doc/1.x/filters/round.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With