convert cents to dollars ("100000" -> "$1,000.00")
<?php
$cents = 100000;
echo "You owe " . Tools::toDollarString($cents);
// You owe $1,000.00
class Tools
{
/**
* Converts cents to dollars
*
* @param int $cents The amount in cents
* @param int $includeDollarSign=true If true the value will be prefixed with a "$" character
* @param int $thousandsSeparator=',' The thousands separator to use if the value is over $999.99
* @return string The amount in dollars
*/
static function toDollarString($cents, $includeDollarSign=true, $thousandsSeparator=',')
{
$return = number_format($cents/100,2,'.',$thousandsSeparator);
if($includeDollarSign)
{
$return = '$'.$return;
}
return $return;
}
}
?>