$sanitizer->float() method

Sanitize to floating point value

Values for getString argument:

  • false (bool): do not return string value (default). 3.0.171+
  • true (bool): locale aware floating point number string. 3.0.171+
  • f (string): locale aware floating point number string (same as true). 3.0.193+
  • F (string): non-locale aware floating point number string. 3.0.193+
  • e (string): lowercase scientific notation (e.g. 1.2e+2). 3.0.193+
  • E (string): uppercase scientific notation (e.g. 1.2E+2). 3.0.193+

Usage

// basic usage
$float = $sanitizer->float($value);

// usage with all arguments
$float = $sanitizer->float($value, array $options = []);

Arguments

NameType(s)Description
valuefloat, string, int
options (optional)array

Optionally specify one or more options in an associative array:

  • precision (int|null): Optional number of digits to round to (default=null)
  • mode (int): Mode to use for rounding precision (default=PHP_ROUND_HALF_UP);
  • blankValue (null|int|string|float): Value to return (whether float or non-float) if provided $value is an empty non-float (default=0.0)
  • min (float|null): Minimum allowed value, excluding blankValue (default=null)
  • max (float|null): Maximum allowed value, excluding blankValue (default=null)
  • `getString (bool|string): Return a string rather than float value? 3.0.171+ (default=false). See value options in method description.

Return value

float string


$sanitizer methods and properties

API reference based on ProcessWire core version 3.0.244

Latest news

  • ProcessWire Weekly #559
    The 559th issue of ProcessWire Weekly brings in all the latest news from the ProcessWire community. Modules, sites, and more. Read on!
    Weekly.pw / 25 January 2025
  • ProcessWire 3.0.244 new main/master version
    ProcessWire 3.0.244 is our newest main/master/stable version. It's been more than a year in the making and is packed with tons of new features, issue fixes, optimizations and more. This post covers all the details.
    Blog / 18 January 2025
  • Subscribe to weekly ProcessWire news

“Indeed, if ProcessWire can be considered as a CMS in its own right, it also offers all the advantages of a CMF (Content Management Framework). Unlike other solutions, the programmer is not forced to follow the proposed model and can integrate his/her ways of doing things.” —Guy Verville, Spiria Digital Inc.