string_format
字符串格式化

Parameter Position参数位置 Type参数类型 Required必需 Default默认 Description描述
1stringYesn/a This is what format to use. (sprintf)
使用的格式化方式

This is a way to format strings, such as decimal numbers and such. Use the syntax for sprintf for the formatting.

是一种格式化字符串的方法.例如格式化为十进制数等等.使用sprintf语法格式化

Example 5-18. string_format
字符串格式化

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