PHP

Numbers

PHP / Numbers

Numbers

Numbers

numbers are data values used to store numeric information such as whole numbers and decimal numbers. PHP automatically recognizes numbers and allows mathematical operations on them.

  • Integer
  • Float
  • Numeric Strings
  • Infinity
  • NaN


 

Example

// Integer (whole number)
$x = 25;
echo "Integer: " . $x;
echo "
";

// Float (decimal number)
$y = 10.5;
echo "Float: " . $y;
echo "
";

// Numeric String (number inside quotes)
$a = "100";
$b = "50";

// PHP automatically converts numeric strings into numbers during calculation
echo "Numeric String Addition: " . ($a + $b);
echo "
";

// Infinity example (division by zero gives infinite value)
$inf = 10 / 0;
echo "Infinity: " . $inf;
echo "
";

// NaN example (invalid mathematical operation)
$nan = sqrt(-1);
echo "NaN: " . $nan;
?>

Technology
PHP
want to connect with us ?
Contact Us