PhpFILTER_VALIDATE_FLOAT floating point verification _ PHP Tutorial

Source: Internet
Author: User
PhpFILTER_VALIDATE_FLOAT floating point number verification. The filter_validate_float filter uses the value as a floating point number for verification. * $ Var12.3; var_dump (filter_var ($ var, filter_validate_float); float (12.3) * non-negative floating point number (positive floating point number + filter_validate_float filter verify the value as a floating point number.
*/
$ 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: http://www.bkjia.com/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
$ 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. 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): retain 2 decimal places and rounding them.

Round (1092,-2): Rounds dozens of rows.

Next, let's introduce 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
?>

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.

*/
?>


The http://www.bkjia.com/PHPjc/445373.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/445373.htmlTechArticlefilter_validate_float filter verifies 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 +...

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.