PHP Number


PHP number variable type includes integer and double.

<?PHP
$id=3;
$value=4.21;
?>

is_int(), is_double(), is_float(), is_real() functions can be used to test the variable is a number or not.
<?PHP
$id=3;
if(is_int($id)) echo "is integer";  //is iteger
else echo "not integer";
if(is_double($id)) echo "is double";
else echo "not double";    //not double
?>

number_format() function formats the number.
<?PHP
$num=1234567;
$num2=number_format($num);
echo "$num2\n";  //1,234,567
?>

mt_rand() function produces a random number. mt_srand() function set a seed for the function mt_rand(), the seed is only needed to be set once.
<?PHP
mt_srand((double)microtime() * 1000000);
$id=mt_rand(3,20); //get a number between 3 and 20
?>