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

后端 未结 4 1892
夕颜
夕颜 2020-12-30 22:53

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

Thanks.

相关标签:
4条回答
  • 2020-12-30 23:22

    string_format accepts sprintf formatting options:

    {$number|string_format:"%.2f"}
    
    0 讨论(0)
  • 2020-12-30 23:26

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

    {$number|round:2}

    0 讨论(0)
  • 2020-12-30 23:39

    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 讨论(0)
  • 2020-12-30 23:46

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

    0 讨论(0)
提交回复
热议问题