| 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 |
math allows the template designer to do math equations in the template. Any numeric template variables may be used in the equations, and the result is printed in place of the tag. The variables used in the equation are passed as parameters, which can be template variables or static values. +, -, /, *, abs, ceil, cos, exp, floor, log, log10, max, min, pi, pow, rand, round, sin, sqrt, srans and tan are all valid operators. Check the PHP documentation for further information on these math functions.
math 讓樣版設計者能夠在樣版中執行數學運算。任何數字形態的樣版變數 都可以在數學等式中使用,且將結果列印在標籤中。等式中的變數,可以是樣版變數或是靜態變 數,都是以參數的方式傳遞。+, -, /, *, abs, ceil, cos, exp, floor, log, log10, max, min, pi, pow, rand, round, sin, sqrt, srans 與 tan 都是可用的運算符號。請參考 PHP 文 件以取得以後數學函式的資訊。
If you supply the special "assign" attribute, the output of the math function will be assigned to this template variable instead of being output to the template.
如果你使用 "assign" 屬性的話,則 math 函式輸出的結果將會被指定給樣版 變數,而不是直接輸出給樣版。
Technical Note: math is an expensive function in performance due to its use of the php eval() function. Doing the math in PHP is much more efficient, so whenever possible do the math calculations in PHP and assign the results to the template. Definately avoid repetitive math function calls, like within section loops.
技術提醒: math 因為使用了 php 的 eval() 函式,所以是相當耗資源的函式,使用 PHP 的數學函式是比較有效率的,所以儘量在 PHP 中作數學運算然後將結果指定給樣版檔案。請儘 量不要使用重複性的數學函式呼叫,如 section 迴圈。