{math}

    {math}允许模板设计者在模板中进行数学运算。

技术注解:{math}是个开销很大的函数,因为它使用了PHP的eval()函数。在PHP中进行数学运算会更加有效。所以在可能的情况下都要在脚本中进行数学运算,然后将结果assign()给模板。绝对要避免重复的{math}函数调用,例如在一个{section}循环中。

属性名 类型 必需? 缺省 描述
equationstringYesn/a 需要执行的等式
formatstringNon/a 结果的格式(sprintf)
varnumericYesn/a 等式变量值
assignstringNon/a 输出所要赋予的模板变量
[var ...]numericYesn/a 等式变量的值

例子8-24. {math}

例子a:

{* $height=4, $width=5 *}

   {math equation="x + y" x=$height y=$width}

    上例将输出:

9

例子b:

{* $row_height = 10, $row_width = 20, #col_div# = 2, assigned in template *}

   {math equation="height * width / division"
   height=$row_height
   width=$row_width
   division=#col_div#}

    上例将输出:

100

例子c:

{* 可以使用括号 *}

   {math equation="(( x + y ) / z )" x=2 y=10 z=2}

    上例将输出:

6

例子d:

{* 你可以提供一个sprintf格式作为格式参数 *}

   {math equation="x + y" x=4.4444 y=5.0000 format="%.2f"}

    上例将输出:

9.44