PHP FILTER_SANITIZE_NUMBER_FLOAT filter

Definition and Usage

FILTER_SANITIZE_NUMBER_FLOAT filter removes all illegal characters from floating-point numbers.

The filter allows all numbers and +-.

  • Name: "number_float"
  • ID-number: 520

Possible flags:

  • FILTER_FLAG_ALLOW_FRACTION - Allow decimal separators (such as .)
  • FILTER_FLAG_ALLOW_THOUSAND - Allow thousand separators (such as ,)
  • FILTER_FLAG_ALLOW_SCIENTIFIC - Allow scientific notation (such as e and E)

Example

<?php

var_dump(filter_var($number, FILTER_SANITIZE_NUMBER_FLOAT,
FILTER_FLAG_ALLOW_FRACTION));
?>

Output:

string(7) "5-2+3.3"