PHP filter_validate_float Floating-point Verification _php Tutorial

Source: Internet
Author: User
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 + ...)

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.