Paypal

# Smarty Icon

You may use the Smarty logo according to the trademark notice.

# Sites Using Smarty

Buy cheap glasses from Cheapglasses123.com and save up to 80%.

Where to buy discount wedding dresses and cheap smart dresses free shipping - Weddingdresstrend.com

Shop for 2018 World Cup Football Boots Online sale at guthjcc.com

Browse best 2018 world cup soccer cleats and shoes from SoccerAzteca.com

## {math}

`{math}`可以让模板设计者在模板中进行一些数学运算。

• 任何在模板中的数字变量都可以进行计算，而计算的结果会替代原来的标签。

• 模板变量或者静态的值都可以作为参数进行计算。

• 可以允许的计算有 +, -, /, *, abs, ceil, cos, exp, floor, log, log10, max, min, pi, pow, rand, round, sin, sqrt, srans 和 tan 。 参见PHP手册，了解math 函数。

• 如果你提供了`assign` 属性， `{math}`函数的输出将不会显示，而是赋值给模板变量。

### 技术说明

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 运算的变量值

Example 8.21. {math}

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

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

```

```
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#}

```

```
100

```

```
{* you can use parenthesis *}

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

```

```
6

```

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

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

```

```
9.44

```

All comments are moderated. Support questions are ignored, use the forums instead.
Author:
Email: (not shown)
What is 19 plus 7? (Are you human?)