InputfieldFloat

Floating point number input

Extends [[InputfieldInteger]] — all integer properties (inputType, min, max, size, placeholder, initValue, defaultValue, range validation, empty-vs-zero behavior, etc.) are inherited and documented there.

$f = $modules->get('InputfieldFloat');
$f->name = 'price';
$f->label = 'Price';
$f->precision = 2;
$f->min = 0;
$form->add($f);

See [[Inputfield]] for the shared Inputfield API.

Properties
PropertyTypeDefaultDescription
precisionint\|null2Decimal places to round to; -1 or null disables rounding 3.0.193+
digitsint0Total significant digits for fixed-decimal (MySQL DECIMAL) mode
noEboolfalseConvert scientific notation (1.23E-4) to a plain decimal in the input 3.0.193+
stepint\|string'any'HTML5 step; defaults to 'any' (allows any decimal); only applies when inputType = 'number'
Precision

precision controls how many decimal places the value is rounded to when set:

$f->precision = 2; // 3.141593.14 (default)
$f->precision = 0; // 3.14 → 3 (integer-like, but float type)
$f->precision = -1; // no rounding applied 3.0.193+

When inputType = 'number' and step is 'any', the step attribute is automatically derived from precision at render time (e.g. precision = 2step = ".01").

Scientific notation

Some locales or data sources produce values in scientific notation (1.5E-3). By default these are passed through as-is. Set noE = true to convert them to plain decimals in the rendered <input>:

$f->noE = true; // 1.5E-3 → 0.0015 in the input element
Locale handling

When inputType = 'number', the value is converted to use . as the decimal separator regardless of locale, because the HTML5 number input requires it. For inputType = 'text', locale-specific separators are preserved.

Notes
  • isEmpty() (inherited from [[InputfieldInteger]]) returns true only for empty string — the float 0.0 is a present, non-empty value.
  • Source file: wire/modules/Inputfield/InputfieldFloat/InputfieldFloat.module
API reference: methods, properties

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

Show class? Show args? Only hookable?

Properties

NameReturnSummary
InputfieldFloat::defaultValue int float string Initial/default value (when used with FieldtypeInteger)
InputfieldFloat::digits int Total digits, for when used in decimal mode
DEFAULT: 0
InputfieldFloat::initValue int float Initial/default value (when used as independent Inputfield)
InputfieldFloat::inputType string Input type to use, one of "text" or "number"
DEFAULT: text
InputfieldFloat::max int float Maximum allowed value
InputfieldFloat::min int float Minimum allowed value
InputfieldFloat::noE bool int Convert “123E-3” and “123E3” type numbers to real numbers in the <input>? 3.0.193+
DEFAULT: false
InputfieldFloat::placeholder string Placeholder attribute for input
DEFAULT: ''
InputfieldFloat::precision int null string Decimals precision (or -1 to disable rounding in 3.0.193+
DEFAULT: 2
InputfieldFloat::size int Size attribute for input
InputfieldFloat::step int float string HTML5 step attibute value
DEFAULT: any

Additional methods and properties

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

API reference based on ProcessWire core version 3.0.267

AltStyle によって変換されたページ (->オリジナル) /