silverstripe-framework/core/model/fieldtypes/Float.php
Ingo Schommer 96a245cb1c 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
2008-04-04 22:55:38 +00:00

52 lines
1.0 KiB
PHP

<?php
/**
* @package sapphire
* @subpackage model
*/
/**
* Represents a floating point field.
* @package sapphire
* @subpackage model
*/
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() {
if($this->countTotalDigits && $this->countDigitsAfterDecimal) {
$sql = "float({$this->countTotalDigits},{$this->countDigitsAfterDecimal})";
} else {
$sql = "float";
}
DB::requireField($this->tableName, $this->name, $sql);
}
function Nice() {
return number_format($this->value, 2);
}
}
?>