A simple introduction to integer types and floating-point numbers in PHP data types

Source: Internet
Author: User
Integral type actually we have been writing, wrote to us 123, my age 12, this is an integral type, or-123, this represents the integer type, that we write is the decimal, but also can write those values, can write octal number, hexadecimal, this represents the integer type. Then we also need to know a storage range for the integral type.

Integer storage range, signed:-2.1 billion, remember a approximate range can be, to the positive of 2.1 billion;-200 million ~21 billion.

The unsigned, that is 0 to 4.2 billion; 0~42 billion;

Floating point (also known as floating point float, double-precision or real real).

The precision of floating-point numbers is limited. Although depending on the system, PHP typically uses IEEE 754 double-precision format, the maximum relative error caused by rounding is 1.11e-16. A non-basic mathematical operation may give greater error and take into account the error transfer during the composite operation.

In addition, a rational number that can be accurately represented in decimal, such as 0.1 or 0.7, cannot be converted to binary format without losing a little bit of precision, regardless of how many of the mantissa can be accurately represented by the binary used internally. This can result in confusion: for example, floor ((0.1+0.7) *10 typically returns 7 instead of 8 as expected because the internal representation of the result is actually similar to 7.9999999999999991118 ....

So never believe that the floating-point number is accurate to the last one, and never compare two floating-point numbers for equality.

This article introduces the integer types of PHP data types and floating-point numbers. Need a friend to reference under

Syntax: integer values can be expressed in decimal, hexadecimal, or octal, preceded by an optional symbol (-or +). Octal indicates that the number must be preceded by 0 (0), and hexadecimal indicates that the number must be preceded by 0x.

$int 1=100; Decimal
$int 2=-123; Negative
$int 3=0123; Octal number
$int 4=0x1a;//Hexadecimal number

echo php_int_size; Displays an integer in a few bytes to represent
echo "<br/>";
echo Php_int_max; echo "<br/>";//integer maximum number (2147483647)
$fmax = 2147483648;
Var_dump (Php_int_max); a number that exceeds the range of integers will be interpreted as a float type.
echo "<br/>";
Var_dump ($fmax);

Floating-point numbers: floating-point numbers (double-precision or real numbers)
$a = 1.34;
$b =1.8e308;
$c =8e-10;
Var_dump ($b);
The length of the floating-point number is relative to the platform, although the usual maximum value is 1.8e308 and has a precision of 14-bit decimal digits (no more than 14 bits)
The precision is calculated from the first non-0 number that begins on the left.

Example: $a = 567.9999899//Output 567.9999899

$b = 789.8812345678543//Output 789.88123456785

$c = 0.000000008907777777//Output 0.000000008907777777

Important understanding: The accuracy is calculated from the first non-0 number starting on the left.

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.