FieldtypeFloat

Stores a floating-point number

Supports single-precision (float) or double-precision (double) database columns.

Value type

float — returns 0.0 when blank (not ''). Zero and blank are equivalent due to zeroNotEmpty behavior (see Notes).

Getting and setting values
// Get
$page->float_field         // float 0.0 when blank)
(float) $page->float_field // same as above; explicit cast for clarity

// Set
$page->float_field = 3.14;
$page->float_field = '';   // clear the value
$page->save('float_field');
Selectors
$pages->find('float_field=3.14');
$pages->find('float_field>1.0');
$pages->find('float_field=""');  // no value
$pages->find('float_field>=1.5, float_field<=9.5'); // range

zeroNotEmpty: by default 0.0 and blank are equivalent — there is no way to distinguish "no value" from "zero" unless zeroNotEmpty is disabled in the field settings.

Notes
  • Default precision is 2 decimal places. Set precision to a different integer, or -1 to disable rounding.
  • Column type is float (single-precision) by default. Switch to double for higher precision when needed.
  • Compatible fieldtypes: FieldtypeFloat, FieldtypeInteger, FieldtypeDecimal, FieldtypeText.
  • Database column: float NOT NULL or double NOT NULL.
API reference: methods, hooks

Click any linked item for full usage details and examples. Hookable methods are indicated with the icon. In addition to those shown below, the FieldtypeFloat class also inherits all the methods and properties of: Fieldtype, WireData and Wire.

Show class?     Show args?       Only hookable?    

Common

NameReturnSummary 
FieldtypeFloat::getBlankValue(Page $page, Field $field)
string

Get blank value

 
FieldtypeFloat::getCompatibleFieldtypes(Field $field)
null Fieldtypes

Get compatible Fieldtypes

FieldtypeFloat::getConfigInputfields(Field $field)
InputfieldWrapper

Get field configuration

FieldtypeFloat::getDatabaseSchema(Field $field)
array

Get DB schema for this Fieldtype

 
FieldtypeFloat::getFieldClass()
string

Get the Field class to use for fields of this type

 
FieldtypeFloat::getInputfield(Page $page, Field $field)
Inputfield

Get Inputfield for this Fieldtype

 
FieldtypeFloat::getMatchQuery(PageFinderDatabaseQuerySelect $query, string $table, string $subfield, string $operator, mixed $value)
PageFinderDatabaseQuerySelect DatabaseQuerySelect

Get the database query that matches a Fieldtype table’s data with a given value.

 
FieldtypeFloat::getPrecision($value)
int

Get precision of given value

 
FieldtypeFloat::isEmptyValue(Field $field, mixed $value)
bool

Is given value considered empty to this Fieldtype?

 
FieldtypeFloat::sanitizeValue(Page $page, Field $field, $value)
float string

Sanitize value

 
FieldtypeFloat::setColumnType(Field $field, string $newType)
string

Set the database data column type (updating the DB table)

 
FieldtypeFloat::sleepValue(Page $page, Field $field, $value)
string

Sleep value for DB storage

FieldtypeFloat::strToFloat(string $str)
float string

Convert float string with commas to float value

 

Additional methods and properties

In addition to the methods and properties above, FieldtypeFloat also inherits the methods and properties of these classes:

API reference based on ProcessWire core version 3.0.260