summaryrefslogtreecommitdiffstats
path: root/system/libraries
diff options
context:
space:
mode:
authorRick Ellis <rick.ellis@ellislab.com>2009-02-24 23:29:37 +0100
committerRick Ellis <rick.ellis@ellislab.com>2009-02-24 23:29:37 +0100
commitdf39d51e3d4f18343666a2e4b991c656d0e61a13 (patch)
tree4c9fac8f73db9544b593fd6a711641f5b654c3da /system/libraries
parenta34a2b2c6761e7a331934f948db6b334a6316cd0 (diff)
Removed the hard coded number formatting and added a "format number" function.
Diffstat (limited to 'system/libraries')
-rw-r--r--system/libraries/Cart.php29
1 files changed, 26 insertions, 3 deletions
diff --git a/system/libraries/Cart.php b/system/libraries/Cart.php
index 61223c597..800c21f75 100644
--- a/system/libraries/Cart.php
+++ b/system/libraries/Cart.php
@@ -32,7 +32,7 @@ class CI_Cart {
// Private variables. Do not change!
var $CI;
- var $_cart_contents = array();
+ var $_cart_contents = array();
/**
@@ -382,7 +382,7 @@ class CI_Cart {
// Set the subtotal
// Note: "subtotal" is a reserved array index. We need to make a note of that in the docs
- $this->_cart_contents[$key]['subtotal'] = number_format(($this->_cart_contents[$key]['price'] * $this->_cart_contents[$key]['qty']), 2);
+ $this->_cart_contents[$key]['subtotal'] = ($this->_cart_contents[$key]['price'] * $this->_cart_contents[$key]['qty']);
}
// Unset these so our total can be calculated correctly below
@@ -420,7 +420,7 @@ class CI_Cart {
*/
function total()
{
- return number_format($this->_cart_contents['cart_total'], 2);
+ return $this->_cart_contents['cart_total'];
}
// --------------------------------------------------------------------
@@ -499,7 +499,30 @@ class CI_Cart {
return $this->_cart_contents[$rowid]['options'];
}
+
+ // --------------------------------------------------------------------
+ /**
+ * Format Number
+ *
+ * Returns the supplied number with commas and a decimal point.
+ *
+ * @access public
+ * @return integer
+ */
+ function format_number($n = '')
+ {
+ if ($n == '')
+ {
+ return '';
+ }
+
+ // Remove anything that isn't a number or decimal point.
+ $n = trim(preg_replace('/([^0-9\.])/i', '', $n));
+
+ return number_format($n, 2, '.', ',');
+ }
+
// --------------------------------------------------------------------
/**