I am using the money_format() function in PHP, which gives the following error:
Fatal error: Call to undefined function money_format()
>
function toMoney($val,$symbol='$',$r=2)
{
$n = $val;
$c = is_float($n) ? 1 : number_format($n,$r);
$d = '.';
$t = ',';
$sign = ($n < 0) ? '-' : '';
$i = $n=number_format(abs($n),$r);
$j = (($j = strlen($i)) > 3) ? $j % 3 : 0;
return $symbol.$sign .($j ? substr($i,0, $j) + $t : '').preg_replace('/(\d{3})(?=\d)/',"$1" + $t,substr($i,$j)) ;
}
echo toMoney(45); ;
output:$45.00