In PHP, numbers are numeric values with or without decimal part and can be negative or positive numbers. PHP has following in numbers.

  1. Integer
  2. Float
  3. Infinity
  4. NaN

Integer

It is whole number without fractional or decimal part, it can be positive or negative number.

Integer Range

BitsRange
32 bits-2147483648 and 2147483647
64 bits-9223372036854775808 and 9223372036854775807

In PHP, Integers can be represented in

Integer NumbersDescriptionExample
base 10decimal23
base 8octal020
base 16hexadecimal0x40
base 2binary0b20

Pre-defined integers constants

PHP_INT_MAXReturns largest integer supported range
PHP_INT_MINReturns smallest integer supported range
PHP_INT_SIZEReturns 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

  1. is_int()
  2. is_integer()
  3. 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_MAXReturns largest floating number supported range
PHP_FLOAT_MINReturns smallest floating number supported range
PHP_FLOAT_DIGSpecifies that the number of decimal digits can be rounded into float and back without precision loss
PHP_FLOAT_EPSILONReturns Smallest positive number

Float Variable

<?php
 $a = 30.5;
?>

Check a variable is float

  1. is_float()
  2. is_double()

Infinity

A number becomes infinity when it is greater than PHP_FLOAT_MAX.

PHP functions to check number is infinite or not

  1. is_finite()
  2. is_infinite()

NaN

PHP, NaN means Not a Number. PHP provides is_NaN() function to check weather a given value is number or not.