PHP supports 8 basic data types.
4 Point type, also called double itself the whole type value 0 (zero)
the float
empty
string, and
containing no elements value can be represented by the constant PHP_INT_SIZE
. Since PHP 4.4.0 and PHP 5.0.5, the maximum value can be represented by the constant PHP_INT_MAX.
If a given number exceeds the range of
. Similarly, if the result of the operation exceeds the range of integer
,float will also be returned. There is no operator for integer division in PHP.
1/2 yields
0.5. You can always discard the decimal part, or use the round() function. To explicitly convert a value to integer, use (int) or
(integer)cast. Most of the time though, no casting is necessary, because when an operator, function, or control flow requires an integer parameter, the value is automatically converted. You can also use the function intval() to convert a value into an integer. Converting
from aboolean , FALSE will yield 0 (zero), TRUE will yield 1 (one). float data type The word length of floating point numbers is platform-dependent, although typically the maximum value is 1.8e308 with a precision of 14 decimal digits (64-bit IEEE format). Apparently simple decimal fractions like 0.1 or 0.7 cannot be converted to the internal binary format without losing a little precision. This can lead to confusing results: for example, floor((0.1+0.7)*10) will usually return 7 instead of the expected 8, because the internal representation of the result is actually something like 7. 9. This is related to the fact that it is impossible to express certain decimal fractions accurately with a finite number of digits. For example, decimal 1/3 becomes 0.3. So never believe that the floating point number result is accurate to the last digit, and never compare whether two floating point numbers are equal. If you really need higher precision, you should use arbitrary precision math functions or the gmp function.
The above introduces the data types. PHP Section 2: Numeric type of data types, including the content of data types. I hope it will be helpful to friends who are interested in PHP tutorials.
Convert from Floating point , when converting from floating point to integer, round towards zero . If the floating point number is outside the integer range (usually +/- 2.15e+9 = 2^31), the result is undefined because there is not enough precision for the floating point number to give an exact integer result. There is no warning in this case, not even any notification!