FEATURE: Ticket #2418 - Merged in patch allow setting of currency symbol

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@53180 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Sean Harvey 2008-04-22 02:12:26 +00:00
parent 91dacf4d15
commit 081905485f

View File

@ -12,16 +12,17 @@
* @subpackage model
*/
class Currency extends Decimal {
protected static $currencySymbol = '$';
function Nice() {
// return "<span title=\"$this->value\">$" . number_format($this->value, 2) . '</span>';
$val = '$' . number_format(abs($this->value), 2);
$val = self::$currencySymbol . number_format(abs($this->value), 2);
if($this->value < 0) return "($val)";
else return $val;
}
function Whole() {
$val = '$' . number_format(abs($this->value), 0);
$val = self::$currencySymbol . number_format(abs($this->value), 0);
if($this->value < 0) return "($val)";
else return $val;
}
@ -32,12 +33,16 @@ class Currency extends Decimal {
$this->value = $value;
} else if(preg_match('/-?\$?[0-9,]+(.[0-9]+)?([Ee][0-9]+)?/', $value, $matches)) {
$this->value = str_replace(array('$',','),'',$matches[0]);
$this->value = str_replace(array('$',',',self::$currencySymbol),'',$matches[0]);
} else {
$this->value = 0;
}
}
static function setCurrencySymbol($value) {
self::$currencySymbol = $value;
}
}
?>