The type is based on the PHP floating point
types, not an arbitrary precision number system.
Available configuration options:
- int precision: The maximum precision that should be kept in then value.
Rounding will happen either during validation or when using the set_value
member function instead of setting the value directly. The PHP function round()
is used for rounding, see its documentation of the precision parameter for further
details. If you set this value to null, rounding is skipped (the default).
- int minimum: The minimum value the type may take, inclusive. Set this to
null to disable the lower bound, which is the default.
- int maximum: The maximum value the type may take, inclusive. Set this to
null to disable the upper bound, which is the default.
Methods
_on_validate ()
The validation callback ensures that we are in the bounds defined by the
type configuration.
The value is rounded prior to processing.
Returns
boolean
Indicating validity.
_round_value ()
Rounds the value according to the precision rules.
If arbitrary precision is set,
no rounding is done, and the function exits without changing the value.
convert_from_csv ($source)
CSV conversion is mapped to regular type conversion.
convert_from_storage (mixed $source)
Explicitly converts the passed value into a float, there is a str_replace()
added to account for possibly broken localized strings (although they shouldn't
happen during saving, you never know).
Parameters
$source
mixed
The storage data structure.
convert_to_csv ()
CSV conversion is mapped to regular type conversion.
convert_to_html ()
Renders localized and rounded to specified precision.
convert_to_storage ()
The current value is converted into a string before being passed to the
caller.
Any decimal characters that are not in a form PHP can recognize
on parsing will be unified before returning them.
This conversion assumes that the current value is already rounded (usually
done by either set_value() or validate().
Returns
string
The string representation of the floating point number.
set_value (float $value)
Wrapper to set the value of this instance type aware: It enforces conversion
to a float type and rounds it to the correct precision if applicable.
This
function should be preferred to regular assignment operations in case you plan
to do further work with the types value.
Special care is taken for string values, which enforce a dot a decimal separator.
Parameters
$value
float
The value to set, enforces float conversion, so you may
assign strings as well, as long as the automatic php float casting works.
Properties
float $maximum
The upper bound of valid values, set to null to disable checking (default).
float $minimum
The lower bound of valid values, set to null to disable checking (default).
int $precision
The precision of the type, null means full available precision, while 0 emulates
an integer type.
See also the PHP round() function's documentation about precision
specifiers.
float $value
The current string encapsulated by this type.
This may be null
for undefined values.