tags:

views:

471

answers:

2

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

Thanks.

+4  A: 

string_format accepts sprintf formatting options:

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

Just use the PHP number_format function:

$formatted_number = number_format(1234.5678, 2);
// $formatted_number then contains 1234.56

Details at http://us.php.net/manual/en/function.number-format.php

Alternatively, if you're trying to format a money amount, try the money_format function. Details at http://us.php.net/manual/en/function.money-format.php.

Brian Showalter
The question was regarding Smarty.
plosww1