Home > Backend Development > PHP Tutorial > php FILTER_VALIDATE_FLOAT floating point number verification_PHP tutorial

php FILTER_VALIDATE_FLOAT floating point number verification_PHP tutorial

WBOY
Release: 2016-07-20 11:02:16
Original
1680 people have browsed it

filter_validate_float filter validates values ​​as floats.
*/
$var=12.3;

var_dump(filter_var($var, filter_validate_float));

//float(12.3)

/*
Non-negative floating point number (positive floating point number + 0): ^d+(.d+)?$
Positive floating point number ^(([0-9]+.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]* .[0-9]+)|([0-9]*[1-9][0-9]*))$
Non-positive floating point number (negative floating point number + 0) ^((-d+(.d+)?)|(0+(.0+)?))$
Negative floating point number ^(-(([0-9]+.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9 ]*.[0-9]+)|([0-9]*[1-9][0-9]*)))$
Floating point number ^(-?d+)(.d+)?
For more details, please see: http://www.bkjia.com/phper/php-function/35065.htm
Here I will introduce to you a method that can calculate the int value closest to the float value multiplied by n. It’s not very clear, so please just look at the code!


Formula: round($number/n)*n
$number=1234.30;
$rounded = round($number / 3) * 3;
echo($rounded);
?>

Result: 1233

1233 can be divided by 3, and 3 is the closest to 1234.30.

As round() is mentioned here, I will introduce its regular usage by the way. Details will be explained in the future.


01.02.echo(round(3.1415927,2)."
");
03.echo(round(1092,-2));
04.?>
echo(round(3.1415927,2)."
");
echo(round(1092,-2));
?>

Result:

3.14
1100

round(3.1415927,2): Keep 2 decimal places for rounding.

round(1092,-2): Round tens digits.

Let me introduce to you a function floor().


01.02.echo floor(4.3); // 4
03.echo floor(9.999); // 9
04.?>
echo floor(4.3); // 4
echo floor(9.999); // 9
?>

Return an integer not greater than value, discarding the decimal part of value. It should be noted here that although the decimal part of value is discarded, the result of floor(value) is still float.

*/
?>


www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/445373.htmlTechArticlefilter_validate_float filter validates the value as a floating point number. */ $var=12.3; var_dump(filter_var($var, filter_validate_float)); //float(12.3) /* Non-negative floating point number (positive floating point number +...
Related labels:
source:php.cn
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