string_format 字符串格式化

优质
小牛编辑
140浏览
2023-12-01

Parameter Position参数位置Type参数类型Required必需Default默认Description描述
1stringYesn/aThis 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