How to round a value in Twig

佐手、 提交于 2019-12-03 14:52:54

问题


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?


回答1:


You could use the format filter for that:

{{ '%.2f'|format(80.5555) }}

But note that it will round it to 80.56.




回答2:


{{ 80.5555 | number_format(2) }}

Here is the documentation number_format




回答3:


Twig documentation says that there's a filter for this task, since 1.15.0:

just write {{80.5555|round}} http://twig.sensiolabs.org/doc/filters/round.html



来源:https://stackoverflow.com/questions/9991157/how-to-round-a-value-in-twig

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!