silverstripe-framework/core/model/fieldtypes/Currency.php
Sam Minnee 397bb5fcc2 #2323: Fix casting of negative currency values; add CurrencyTest unit testing
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@51145 467b73ca-7a2a-4603-9d3b-597d59a354a9
2008-03-17 02:10:23 +00:00

34 lines
724 B
PHP

<?php
/**
* @package sapphire
* @subpackage model
*/
/**
* Represents a decimal field containing a currency amount.
* Currency the currency class only supports single currencies.
* @package sapphire
* @subpackage model
*/
class Currency extends Decimal {
function Nice() {
// return "<span title=\"$this->value\">$" . number_format($this->value, 2) . '</span>';
$val = '$' . number_format(abs($this->value), 2);
if($this->value < 0) return "($val)";
else return $val;
}
function Whole() {
$val = '$' . number_format(abs($this->value), 0);
if($this->value < 0) return "($val)";
else return $val;
}
function setValue($value) {
$this->value = ereg_replace('[^0-9.\-]+','', $value);
}
}
?>