From df47669c0e3ff8ddc8c369aa72dcc5e66085e616 Mon Sep 17 00:00:00 2001 From: pzinovkin Date: Tue, 17 Feb 2009 11:20:01 +0000 Subject: [PATCH] show/hide decimals for money git-svn-id: svn+ssh://code.netmonsters.ru/svn/majestic/trunk@64 4cb57b5f-5bbd-dd11-951b-001d605cbbc5 --- classes/Format.class.php | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/classes/Format.class.php b/classes/Format.class.php index ac66746..6dfb8b3 100644 --- a/classes/Format.class.php +++ b/classes/Format.class.php @@ -36,12 +36,21 @@ class Format return self::$currency_symbol; } - static public function int2money($int = 0, $currency = false) + /** + * Форматируем int в денежный формат + * + * @param mixed $int + * @param bool $currency - показывать валюту + * @param bool $show_decimals - показывать или нет дробную часть + */ + static public function int2money($int = 0, $currency = false, $show_decimals = true) { - if(!isset(self::$cache_money[$int])){ - self::$cache_money[$int] = number_format($int/100, self::$frac_digits, self::$decimal_point, ' '); + $key = $int . '_' . (int)$currency . '_' . (int)$show_decimals; + + if(!isset(self::$cache_money[$key])){ + self::$cache_money[$key] = number_format($int/100, ($show_decimals) ? self::$frac_digits : 0, self::$decimal_point, ' '); } - return self::$cache_money[$int] . (($currency) ? ' '.self::$currency_symbol : ''); + return self::$cache_money[$key] . (($currency) ? ' '.self::$currency_symbol : ''); } static public function money2int($money)