Friday, June 22, 2012

PHP function number_format

Sometimes we may require the output number is formated in PHP.  For example we need format
$ 1.2 to $1.20 and $1.223 to $1.22.  We can use PHP function  number_format.
PHP function number_format  sets the number of decimal points.
for example
echo number_format($amount,2);
will produce 1.20 output.
similar function sprintf
sprintf("%01.2f", $amount);
will produce the same result.

No comments:

Post a Comment