__('Float', __FILE__), // Module Title 'summary' => __('Floating point number with precision', __FILE__), // Module Summary 'version' => 102, 'permanent' => true, ); } public function __construct() { $this->set('precision', 2); parent::__construct(); } public function init() { parent::init(); $this->attr('step', 'any'); // HTML5 attr required to support decimals with 'number' types } protected function sanitizeValue($value) { $precision = $this->precision; if(is_null($precision)) $precision = FieldtypeFloat::getPrecision($value); return strlen("$value") ? round((float) $value, $precision) : ''; } /** * Returns true if number is in valid range, false if not * * Overriding the function from InputfieldInteger to ensure float types (rather than int types) are used * */ protected function isInRange($value) { $inRange = true; $min = $this->attr('min'); $max = $this->attr('max'); if(strlen("$value")) { if(strlen("$min") && ((float) $value) < ((float) $min)) { $inRange = false; } if(strlen("$max") && ((float) $value) > ((float) $max)) { $inRange = false; } } return $inRange; } }