开发者

Is it possible to format a number to 2 decimal places with Smarty PHP

开发者 https://www.devze.com 2022-12-22 14:21 出处:网络
Is it possible to format a number to 2 decimal places with Smart开发者_运维百科y PHP? Thanks.string_format accepts sprintf formatting options:

Is it possible to format a number to 2 decimal places with Smart开发者_运维百科y PHP?

Thanks.


string_format accepts sprintf formatting options:

{$number|string_format:"%.2f"}


{$number|number_format:2} is what you want


You can use the round function, though it will not add decimal places only remove them:

{$number|round:2}


To display 2 instead of 2.00 you can use : replace in Smarty PHP

See below example -

$number = 2.00

{$number|replace:'.00':''}

Output :- 2 

Hope this helps.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号