Home > Backend Development > PHP Tutorial > FILTER_SANITIZE_NUMBER_FLOAT constant in PHP

FILTER_SANITIZE_NUMBER_FLOAT constant in PHP

PHPz
Release: 2023-08-29 19:06:01
forward
1138 people have browsed it

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));
?>
Copy after login

Output

The following is the output.

string(8) "3-1+2.56"
Copy after login

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));
?>
Copy after login

Output

This is the output.

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

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!

Related labels:
source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template