2007-07-19 12:40:28 +02:00
|
|
|
<?php
|
2008-02-25 03:10:37 +01:00
|
|
|
/**
|
|
|
|
* Represents a floating point field.
|
|
|
|
* @package sapphire
|
|
|
|
* @subpackage model
|
2007-07-19 12:40:28 +02:00
|
|
|
*/
|
|
|
|
class Float extends DBField {
|
|
|
|
|
|
|
|
function requireField() {
|
2009-09-30 00:01:15 +02:00
|
|
|
$parts=Array('datatype'=>'float', 'arrayValue'=>$this->arrayValue);
|
2008-11-23 02:01:03 +01:00
|
|
|
$values=Array('type'=>'float', 'parts'=>$parts);
|
|
|
|
DB::requireField($this->tableName, $this->name, $values);
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function Nice() {
|
|
|
|
return number_format($this->value, 2);
|
2008-08-06 04:43:46 +02:00
|
|
|
}
|
|
|
|
|
2008-08-13 00:47:08 +02:00
|
|
|
function Round($precision = 3) {
|
|
|
|
return round($this->value, $precision);
|
|
|
|
}
|
|
|
|
|
|
|
|
function NiceRound($precision = 3) {
|
|
|
|
return number_format(round($this->value, $precision), $precision);
|
|
|
|
}
|
|
|
|
|
2008-08-06 04:43:46 +02:00
|
|
|
public function scaffoldFormField($title = null) {
|
|
|
|
return new NumericField($this->name, $title);
|
|
|
|
}
|
2008-09-11 08:22:33 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Return an encoding of the given value suitable for inclusion in a SQL statement.
|
|
|
|
* If necessary, this should include quotes.
|
|
|
|
*/
|
|
|
|
function prepValueForDB($value) {
|
|
|
|
if($value === true) {
|
|
|
|
return 1;
|
|
|
|
} if(!$value || !is_numeric($value)) {
|
2009-10-01 23:03:52 +02:00
|
|
|
if(strpos($value, '[')===false)
|
|
|
|
return '0';
|
|
|
|
else
|
|
|
|
return addslashes($value);
|
2008-09-11 08:22:33 +02:00
|
|
|
} else {
|
|
|
|
return addslashes($value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
2008-11-23 02:01:03 +01:00
|
|
|
?>
|