From e81802d0cd00f53e0bc0b29e9f462a5bec275d82 Mon Sep 17 00:00:00 2001 From: Nathan Gray Date: Mon, 28 Feb 2011 20:31:56 +0000 Subject: [PATCH] Promote number_format() to base class so it's available for all extending classes --- etemplate/inc/class.bo_merge.inc.php | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/etemplate/inc/class.bo_merge.inc.php b/etemplate/inc/class.bo_merge.inc.php index 70a42462d8..1997f178d4 100644 --- a/etemplate/inc/class.bo_merge.inc.php +++ b/etemplate/inc/class.bo_merge.inc.php @@ -803,4 +803,26 @@ abstract class bo_merge public static function get_file_extensions() { return array('txt', 'rtf', 'odt', 'ods', 'docx', 'xml'); } + + /** + * Format a number according to user prefs with decimal and thousands separator + * + * Reimplemented from etemplate to NOT use user prefs for Excel 2003, which gives an xml error + * + * @param int|float|string $number + * @param int $num_decimal_places=2 + * @param string $_mimetype='' + * @return string + */ + static public function number_format($number,$num_decimal_places=2,$_mimetype='') + { + if ((string)$number === '') return ''; + //error_log(__METHOD__.$_mimetype); + switch($_mimetype) + { + case 'application/xml': // Excel 2003 + return number_format(str_replace(' ','',$number),$num_decimal_places,'.',''); + } + return etemplate::number_format($number,$num_decimal_places); + } }