smarty中math函數的用法


在查看項目代碼時,發現smart代碼中有這樣寫。

{if $auctionInfo.printingNum}
    印數:{math equation="cid/1000" cid=$auctionInfo.printingNum format="%d"}千冊<br />
{/if}

意思是:把$auctionInfo.printingNum 的值賦值給cid,cid/1000,后面format是格式,數值型,如果要保留一位  format = "%.1f" ,保留兩位 format = "%.2f"

以下是官網給舉例子:

Example 8.24. {math}

Example a:

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

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

 

The above example will output:

   9

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

The above example will output:

   100

Example c:

   {* you can use parenthesis *}

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

The above example will output:

   6

Example d:

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

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

The above example will output:

   9.44

  url:http://www.smarty.net/docsv2/en/language.function.math.tpl


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM