我在树枝文件中有以下两个变量。
{%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%}
Run Code Online (Sandbox Code Playgroud)
当我要划分这个得到这个错误时:
An exception has been thrown during the rendering of a template ("Notice: Object of class Twig_Markup could not be converted to int...
Run Code Online (Sandbox Code Playgroud)
我需要得到这样的百分比
{{ (sanstha_actual/sanstha_target)*100}}
Run Code Online (Sandbox Code Playgroud)
小智 7
我认为你必须使用两个斜线,即
{{ (sanstha_actual // sanstha_target) * 100 }}
Run Code Online (Sandbox Code Playgroud)
如文档所示:
//: 将两个数字相除并返回地板整数结果。{{ 20 // 7 }} 是 2