In PHP, numbers are numeric values with or without decimal part and can be negative or positive numbers. PHP has following in numbers.
- Integer
- Float
- Infinity
- NaN
Integer
It is whole number without fractional or decimal part, it can be positive or negative number.
Integer Range
Bits | Range |
---|---|
32 bits | -2147483648 and 2147483647 |
64 bits | -9223372036854775808 and 9223372036854775807 |
In PHP, Integers can be represented in
Integer Numbers | Description | Example |
---|---|---|
base 10 | decimal | 23 |
base 8 | octal | 020 |
base 16 | hexadecimal | 0x40 |
base 2 | binary | 0b20 |
Pre-defined integers constants
PHP_INT_MAX | Returns largest integer supported range |
PHP_INT_MIN | Returns smallest integer supported range |
PHP_INT_SIZE | Returns Integer size in bytes |
Integer variable
<?php
$a = 30;
?>
$a variable holds value 30, so, it behaves as integer variable.
Check variable is Integer variable or not
<?php
$a = 30;
var_dump($a);
?>
PHP function to check a variable is integer or not
- is_int()
- is_integer()
- is_long()
Floats
float value is a number with fractional or decimal part or in Exponential form. It can be either negative number or positive number. PHP allows to store float numbers with 14 digit maximum precision and numbers upto 1.7976931348623E+308. Float value is also called double or real numbers.
PHP_FLOAT_MAX | Returns largest floating number supported range |
PHP_FLOAT_MIN | Returns smallest floating number supported range |
PHP_FLOAT_DIG | Specifies that the number of decimal digits can be rounded into float and back without precision loss |
PHP_FLOAT_EPSILON | Returns Smallest positive number |
Float Variable
<?php
$a = 30.5;
?>
Check a variable is float
- is_float()
- is_double()
Infinity
A number becomes infinity when it is greater than PHP_FLOAT_MAX.
PHP functions to check number is infinite or not
- is_finite()
- is_infinite()
NaN
PHP, NaN means Not a Number. PHP provides is_NaN() function to check weather a given value is number or not.