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

 ̄綄美尐妖づ 提交于 2019-12-18 12:46:16

问题


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

Thanks.


回答1:


string_format accepts sprintf formatting options:

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



回答2:


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




回答3:


{$number|round:"2"} also works




回答4:


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.



来源:https://stackoverflow.com/questions/2409110/is-it-possible-to-format-a-number-to-2-decimal-places-with-smarty-php

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!