Reputation: 1009
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?
Upvotes: 23
Views: 14946
Reputation: 1022
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
Upvotes: 3
Reputation: 44841
You could use the format filter for that:
{{ '%.2f'|format(80.5555) }}
But note that it will round it to 80.56
.
Upvotes: 30
Reputation: 1564
{{ 80.5555 | number_format(2) }}
Here is the documentation number_format
Upvotes: 32