# PHP Learning Record (float type) _ PHP Tutorial

Source: Internet
Author: User
PHP learning Records (float type ).? Php \$ a1.234; \$ b1.2e3; \$ c7E-10 ;? Regular expression: Floating point: [0-9] + double precision: ([0-9] [.] {LNUM}) | ({LNUM} [.] [0-9] *) exponential expression: [+-]? ({LNUM} | {DNU \$ A = 1.234;
\$ B = 1.2e3;
\$ C = 7E-10;
?>

The regular expression is as follows:

Floating point: [0-9] +
Double precision: ([0-9] [.] {LNUM}) | ({LNUM} [.] [0-9] *)
Exponential expression: [+-]? ({LNUM} | {DNUM}) [eE] [+-]? {LNUM })

======================================
The php code for the maximum floating point number is as follows:
Function float_max (\$ mul = 2, \$ affine = 1 ){
\$ Max = 1; \$ omax = 0;
While (string) \$ max! = 'Inf ') {\$ omax = \$ max; \$ max * = \$ mul ;}

For (\$ I = 0; \$ I <\$ affine; \$ I ++ ){
\$ Pmax = 1; \$ max = \$ omax;
While (string) \$ max! = 'Inf '){
\$ Omax = \$ max;
\$ Max + = \$ pmax;
\$ Pmax * = \$ mul;
}
}
Return \$ omax;
}
Echo "maximum floating point:"; var_dump (float_max ());
?>
======================================
The results are as follows (related to the platform ):
Maximum floating point: float (1.79769313486E + 308)

Precautions for floating point precision:

A simple decimal fraction, like 0.1 or 0.7, is converted to an internal binary format, which will result in loss of precision:
For example, floor (0.1 + 0.7) * 10) usually returns 7 instead of the expected 8, because the internal representation of this result is actually 7.9.
It is impossible to accurately express certain decimal scores with limited digits.
For example, the value of decimal 1/3 is 0.3.
So
1. Never believe that the result of a floating point number is accurate to the last digit,
2. Do not compare two floating point numbers for equality.
3. If higher precision is required, use any precision mathematical function or gmp function.

From PHP 5, if you try to convert an object to a floating point number, an E_NOTICE error will be issued.

Http://www.bkjia.com/PHPjc/371639.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/371639.htmlTechArticle? Php \$ a = 1.234; \$ B = 1.2e3; \$ c = 7E-10 ;? Regular expression: Floating point: [0-9] + double precision: ([0-9] [.] {LNUM}) | ({LNUM} [.] [0-9] *) exponential expression: [+-]? ({LNUM} | {DNU...

Related Keywords:

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.