From 96a245cb1cd7de49d36d8fb6d5c66ba0f9430e13 Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Fri, 4 Apr 2008 22:55:38 +0000 Subject: [PATCH] Merged revisions 46566 via svnmerge from svn://svn.silverstripe.com/silverstripe/modules/sapphire/branches/2.2.0-mesq ........ r46566 | ischommer | 2007-12-11 10:16:22 +1300 (Tue, 11 Dec 2007) | 1 line Allowing precision in Float, e.g. "Float(10,5)" ........ git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@52152 467b73ca-7a2a-4603-9d3b-597d59a354a9 --- core/model/fieldtypes/Float.php | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/core/model/fieldtypes/Float.php b/core/model/fieldtypes/Float.php index 9834e6fd6..b00caac20 100644 --- a/core/model/fieldtypes/Float.php +++ b/core/model/fieldtypes/Float.php @@ -12,8 +12,36 @@ */ class Float extends DBField { + /** + * Allows for setting the digits before decimal point + * e.g. a value of 7 can be -99999.99 + * + * @var int + */ + protected $countTotalDigits; + + /** + * Allows for setting the digits before decimal point + * e.g. a value of 4 can be -999.9999 + * + * @var int + */ + protected $countDigitsAfterDecimal; + + function __construct($name, $countTotalDigits, $countDigitsAfterDecimal) { + $this->countTotalDigits = $countTotalDigits; + $this->countDigitsAfterDecimal = $countDigitsAfterDecimal; + + parent::__construct($name); + } + function requireField() { - DB::requireField($this->tableName, $this->name, "float"); + if($this->countTotalDigits && $this->countDigitsAfterDecimal) { + $sql = "float({$this->countTotalDigits},{$this->countDigitsAfterDecimal})"; + } else { + $sql = "float"; + } + DB::requireField($this->tableName, $this->name, $sql); } function Nice() {