Home  >  Article  >  Backend Development  >  FILTER_SANITIZE_NUMBER_FLOAT constant in PHP

FILTER_SANITIZE_NUMBER_FLOAT constant in PHP

PHPz
PHPzforward
2023-08-29 19:05:031122browse

FILTER_SANITIZE_NUMBER_FLOAT constant in PHP

FILTER_SANITIZE_NUMBER_FLOAT constant removes all illegal characters from floating point numbers.

Flags

  • FILTER_FLAG_ALLOW_FRACTION - allows fraction delimiter

  • FILTER_FLAG_ALLOW_THOUSAND - Allow thousands separators

  • FILTER_FLAG_ALLOW_SCIENTIFIC - Allow scientific notation

Returns

The FILTER_SANITIZE_NUMBER_FLOAT constant returns nothing.

Example

The following is an example of using the FILTER_FLAG_ALLOW_FRACTION flag.

Real-time demonstration

<?php
   $var = "3-1f+2.56p";
   var_dump(filter_var($var, FILTER_SANITIZE_NUMBER_FLOAT,
   FILTER_FLAG_ALLOW_FRACTION));
?>

Output

The following is the output.

string(8) "3-1+2.56"

Let’s look at another example. The FILTER_FLAG_ALLOW_THOUSAND flag is used here -

Example

Live Demonstration

<?php
   $var = "1-4f+25,6p";
   var_dump(filter_var($var, FILTER_SANITIZE_NUMBER_FLOAT,
   FILTER_FLAG_ALLOW_THOUSAND));
?>

Output

This is the output.

string(8) "1-4+25,6"

The above is the detailed content of FILTER_SANITIZE_NUMBER_FLOAT constant in PHP. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete