The Filter_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 + 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 ^ (-?d+) (. d+)?
For more detailed information, please see: http://www.bkjia.com/phper/php-function/35065.htm
Here's a way to figure out how to multiply the value of an int with n multiplied by the nearest float. Not very clear, so please read the code directly!
Formula: Round ($number/N) *n
$number = 1234.30;
$rounded = Round ($number/3) * 3;
Echo ($rounded);
?>
Results: 1233
1233 can be divisible by 3, and divisible by 3 is the closest to 1234.30.
The round () is mentioned here, and the general usage of it is introduced, and the detailed explanation will be given later.
02.echo (Round (3.1415927,2). "
");
03.echo (Round (1092,-2));
04.?>
Echo (Round (3.1415927,2).
");
Echo (Round (1092,-2));
?>
Results:
3.14
1100
Round (3.1415927,2): 2 decimal places are reserved for rounding.
Round (1092,-2): Rounds the 10-digit number.
Let me introduce you to a function floor ().
02.echo floor (4.3);//4
03.echo floor (9.999); 9
04.?>
echo floor (4.3); 4
echo Floor (9.999); 9
?>
Returns an integer that is not less than value, discarding the fractional part of value. It is important to note that although value is discarded for the decimal part, the result of floor (value) is still float.
*/
?>
http://www.bkjia.com/PHPjc/445373.html www.bkjia.com true http://www.bkjia.com/PHPjc/445373.html techarticle The Filter_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 + ...)