BUGFIX: Allow percentage fields to store 100%

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/branches/2.2@83164 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Andrew O'Neil 2009-07-29 23:35:42 +00:00 committed by Sam Minnee
parent e798007f0a
commit e33a314256
2 changed files with 12 additions and 3 deletions

View File

@ -44,4 +44,4 @@ class Decimal extends DBField {
}
}
?>
?>

View File

@ -20,12 +20,21 @@ class Percentage extends Decimal {
if( !$precision )
$precision = 4;
parent::__construct($name, $precision, $precision);
parent::__construct($name, $precision + 1, $precision);
}
function Nice() {
return number_format($this->value * 100, $this->decimalSize - 2) . '%';
}
function saveInto($dataObject) {
parent::saveInto($dataObject);
$fieldName = $this->name;
if($fieldName && $dataObject->$fieldName > 1.0) {
$dataObject->$fieldName = 1.0;
}
}
}
?>
?>