<?
class DecimalHelper extends AppHelper {

    function formatDecimal($num) {
	if(floor($num) == $num) { //whole number.
	    $formatted = number_format($num, 0);
	}
	else {
	    $formatted = number_format($num, 2);
	}

	return $this->output($formatted);
    }

    function formatMoney($number, $cents = 1) { // cents: 0=never, 1=if needed, 2=always
	if (is_numeric($number)) { // a number
	    if (!$number) { // zero
		$money = ($cents == 2 ? '0.00' : '0'); // output zero
	    } else { // value
		if (floor($number) == $number) { // whole number
		    $money = number_format($number, ($cents == 2 ? 2 : 0)); // format
		} else { // cents
		    $money = number_format(round($number, 2), ($cents == 0 ? 0 : 2)); // format
		} // integer or decimal
	    } // value
	    return '$'.$money;
	} // numeric
    } // formatMoney

}

?>
