|
Posted by NC on 12/15/05 01:28
TonyG wrote:
>
> what's the best way to convert a string value to a currency format?
>
> String : 12.5
> Output: $12.50
Try this:
function moneyFormat($number, $currencySymbol = '$',
$decPoint = '.', $thousandsSep = ',', $decimals = 2) {
return $currencySymbol . number_format($number, $decimals,
$decPoint, $thousandsSep);
}
Simple usage example:
echo moneyFormat(1234.5);
// outputs $1,234.50
Slightly more complicated usage examples:
echo moneyFormat(1234.5, 'EUR ', ',', '.');
// outputs EUR 1.234,50
echo "Gasoline price: ",
moneyFormat(2.499, '$', '.', ',', 3),
" per gallon";
// outputs Gasoline price: $2.499 per gallon
Cheers,
NC
Navigation:
[Reply to this message]
|