我在 Twig 文件中有以下两个变量。
{%set sanstha_target%}
{%render 'FrontBundle:Datasheet:getCurrentTarget' with {'dealer':recent_entry.id,'month':recent_entry.year~recent_entry.month,'type':'3'}%}
{%endset%}
{%set sanstha_actual%}
{%render 'FrontBundle:Datasheet:getTotal' with {'datasheet':recent_entry.datasheet,'dealer':recent_entry.id,'type':'3'}%}
{%endset%}
当我要划分这个得到这个错误时:
An exception has been thrown during the rendering of a template ("Notice: Object of class Twig_Markup could not be converted to int...
我需要得到这样的百分比
{{ (sanstha_actual/sanstha_target)*100}}
最佳答案
我认为你必须使用两个斜线,即
{{ (sanstha_actual // sanstha_target) * 100 }}
如 documentation 所示:
//: Divides two numbers and returns the floored integer result. {{ 20 // 7 }} is 2
关于symfony - Twig 文件中两个变量的除法。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23760183/