math

PHP Smarty

Smarty - the compiling PHP template engine
Smarty - php 模板编译引擎
Prev 来源:PHP中文社区 Chapter 8. Custom Functions[第八章.自定义函数] Next

math

Attribute Name Type Required Default Description
equation string Yes n/a the equation to execute
format string No n/a the format of the result (sprintf)
var numeric Yes n/a equation variable value
assign string No n/a template variable the output will be assigned to
[var ...] numeric Yes n/a equation variable value

属性 类型 是否必须 缺省值 描述
equation string Yes n/a 待执行的表达式
format string No n/a 结果的格式(遵从sprintf函数)
var numeric Yes n/a 表达式变量值
assign string No n/a 输出值将被赋给模板变量的名称
[var ...] numeric Yes n/a 表达式变量值
{* $height=4, $width=5 *}

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

OUTPUT:

9


{* $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#}

OUTPUT:

100


{* you can use parenthesis *}

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

OUTPUT:

6


{* you can supply a format parameter in sprintf format *}

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

OUTPUT:

9.44

Prev 来源:PHP中文社区 Home Next
html_table Up mailto