1 <?php
2 3 4 5 6 7 8 9 10
11 class Currency extends Decimal {
12 protected static $currencySymbol = '$';
13
14 function Nice() {
15
16 $val = self::$currencySymbol . number_format(abs($this->value), 2);
17 if($this->value < 0) return "($val)";
18 else return $val;
19 }
20
21 function Whole() {
22 $val = self::$currencySymbol . number_format(abs($this->value), 0);
23 if($this->value < 0) return "($val)";
24 else return $val;
25 }
26
27 function setValue($value) {
28 $matches = null;
29 if(is_numeric($value)) {
30 $this->value = $value;
31
32 } else if(preg_match('/-?\$?[0-9,]+(.[0-9]+)?([Ee][0-9]+)?/', $value, $matches)) {
33 $this->value = str_replace(array('$',',',self::$currencySymbol),'',$matches[0]);
34
35 } else {
36 $this->value = 0;
37 }
38 }
39
40 static function setCurrencySymbol($value) {
41 self::$currencySymbol = $value;
42 }
43 }
44
45 ?>
[Raise a SilverStripe Framework issue/bug](https://github.com/silverstripe/silverstripe-framework/issues/new)
- [Raise a SilverStripe CMS issue/bug](https://github.com/silverstripe/silverstripe-cms/issues/new)
- Please use the
Silverstripe Forums to ask development related questions.
-