The filter_validate_float filter uses the value as a floating point number for verification.
*/
$ Var = 12.3;
Var_dump (filter_var ($ var, filter_validate_float ));
// Float (1, 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, see php Tutorial er/php-function/35065.htm"> http://www.111cn.net/phper/php-function/35065.htm
Here we will introduce you to a method that can calculate the int value that doubles n to the nearest float value. I am not very clear about it. Please read the code directly!
Formula: round ($ number/n) * n
<? Php
$ Number = 1234.30;
$ Rounded = round ($ number/3) * 3;
Echo ($ rounded );
?>
Result: 1233
1233 can be divided into 3, and 3 is the closest to 1234.30.
Here, we will introduce the general usage of round (), which will be described in detail later.
01. <? Php
02. echo (round (3.1415927, 2). "<br/> ");
03. echo (round (1092,-2 ));
04.?>
<? Php
Echo (round (3.1415927, 2). "<br/> ");
Echo (round (1092,-2 ));
?>
Result:
3.14
1100
Round (3.1415927, 2): retain 2 decimal places and rounding them.
Round (1092,-2): Rounds dozens of rows.
Next, let's introduce a function floor ().
01. <? Php
02. echo floor (4.3); // 4
03. echo floor (9.999); // 9
04.?>
<? Php
Echo floor (4.3); // 4
Echo floor (9.999); // 9
?>
Returns an integer not greater than the value. The fractional part of the value is discarded. Note that although the value is discarded from the fractional part, the result obtained by floor (value) is still float.
*/
?>