From e33a314256fc0ccff59dfeef88326d9bc7d19c74 Mon Sep 17 00:00:00 2001 From: Andrew O'Neil Date: Wed, 29 Jul 2009 23:35:42 +0000 Subject: [PATCH] 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 --- core/model/fieldtypes/Decimal.php | 2 +- core/model/fieldtypes/Percentage.php | 13 +++++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/core/model/fieldtypes/Decimal.php b/core/model/fieldtypes/Decimal.php index b8d5ea301..a83b6afdc 100644 --- a/core/model/fieldtypes/Decimal.php +++ b/core/model/fieldtypes/Decimal.php @@ -44,4 +44,4 @@ class Decimal extends DBField { } } -?> \ No newline at end of file +?> diff --git a/core/model/fieldtypes/Percentage.php b/core/model/fieldtypes/Percentage.php index 65194aaa6..64d59a99a 100644 --- a/core/model/fieldtypes/Percentage.php +++ b/core/model/fieldtypes/Percentage.php @@ -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; + } + } } -?> \ No newline at end of file +?>