一种格式化字符串的方法.例如格式化为十进制数等等.使用sprintf语法格式化
字符串格式化
index.php:
$smarty = new Smarty;
$smarty->assign("number", 23.5787446);
$smarty->display("index.tpl");
index.tpl:
{$number}
{$number|string_format:"%.2f"}
{$number|string_format:"%d"}
OUTPUT:
23.5787446
23.58
24
例2
代码如下
{foreach item=row key=page from=$result}
{$row.DECLAREDATE}
{$row.DYZ|string_format:"%01.2f"}
{$row.DYTB|string_format:"%01.2f"}
{$row.LJZ|string_format:"%01.2f"}
{$row.LJTB|string_format:"%01.2f"}
{/foreach}
php smarty|smarty中string_format 字符串格式化
http://m.bbyears.com/jiaocheng/37511.html
推荐访问:smarty模板的作用