Version: current

     1 <?php
     2 /**
     3  * Represents a decimal field containing a currency amount.
     4  * Currency the currency class only supports single currencies.
     5  *
     6  * @deprecated 2.5 Use Money class
     7  *
     8  * @package sapphire
     9  * @subpackage model
    10  */
    11 class Currency extends Decimal {
    12     protected static $currencySymbol = '$';
    13
    14     function Nice() {
    15         // return "<span title=\"$this->value\">$" . number_format($this->value, 2) . '</span>';
    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. -