如果您使用 Smarty 3,我强烈建议您放弃 {math}:
{$order_total = 123}
{$commission = 13}
{$discount = 10}
{$delivery_charge = 20}
{$rate = 1.1}
{$result = 0}
{$result = $result + ($order_total - $commission + $discount + $delivery_charge) * $rate}
{$result}
它可读性更好,速度更快(因为表达式实际上是编译的,而不是eval()ed
一遍又一遍地编译)。
Smarty 2 等价物:
{assign var="order_total" value=123}
{assign var="commission" value=13}
{assign var="discount" value=10}
{assign var="delivery_charge" value=20}
{assign var="rate" value=1.1}
{assign var="result" value=0}
{math
assign="result"
equation="result + (order_total - commission + discount + delivery_charge) * rate"
result=$result
order_total=$order_total
commission=$commission
discount=$discount
delivery_charge=$delivery_charge
rate=$rate
}
{$result}
如果有任何机会升级到 Smarty 3 - 去做吧!