$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+


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

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


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.225

Latest news

  • ProcessWire Weekly #489
    In the 489th issue of ProcessWire Weekly we'll check out what's new in the core this week, share a brand-new recipe of the week, and more. Read on!
    Weekly.pw / 23 September 2023
  • ProcessWire 3.0.226 new main/master version
    After 8 months in development we are excited to bring you ProcessWire 3.0.226 main/master. This version has a ton of great new features, improvements and optimizations, plus more than 100 issue fixes. This post takes an in-depth look at highlights from this great new version.
    Blog / 25 August 2023
  • Subscribe to weekly ProcessWire news

“We were really happy to build our new portfolio website on ProcessWire! We wanted something that gave us plenty of control on the back-end, without any bloat on the front end - just a nice, easy to access API for all our content that left us free to design and build however we liked.” —Castus, web design agency in Sheffield, UK