Table of Contents
<h4>php-number</h2>
<p>There are three main numeric types in PHP: Integer, Float, Number Strings</p>
<p>In addition, PHP has two more data types used for numbers:Infinity, NaN</p>
<?php
$a = 5;
$b = 5.34;
$c = "25";
var_dump($a); // Result: int(5)
echo "<br>";
var_dump($b); // Result: float(5.34)
echo "<br>";
var_dump($c); // Result: string(2) "25"
?>
Result View Example
<h4>php-number-Integers</h2>
<p>An integer data type is a non-decimal number between -2147483648 and 2147483647 in 32 bit systems, and between -9223372036854775808 and 9223372036854775807 in 64 bit systems. A value greater (or lower) than this, will be stored as float, because it exceeds the limit of an integer.</p>
<?php
// Check if the type of a variable is integer
$x = 5985;
var_dump(is_int($x)); // Result: bool(true)
echo "<br>";
// Check again...
$x = 59.85;
var_dump(is_int($x)); // Result: bool(false)
?>
Result View Example
<h4>php-number-float</h2>
<p>A float is a number with a decimal point or a number</p>
<?php
// Check if the type of a variable is float
$x = 10.365;
var_dump(is_float($x)); // Result: bool(true)
?>
Result View Example
<h4>php-number infinity</h4>
<p>There are three main numeric types in PHP:</p>
<?php
// Check if a numeric value is finite or infinite
$x = 1.9e411;
var_dump($x); // Result: float(INF)
?>
Result View Example
NaN stands for Not a Number.
NaN is used for impossible mathematical operations.
PHP has the following functions to check if a value is not a number:
<h4>NaN</h4>
<p>Invalid calculation will return a NaN value:</p>
<?php
// Invalid calculation will return a NaN value
$x = acos(1.01);
var_dump($x); // Result: float(NAN)
Result View Example
Lorem ipsum dolor sit, amet consectetur adipisicing elit. Odio porro similique eveniet tenetur voluptas at? Perferendis sunt temporibus fuga in?
Result View Example
Document in project
You can Download PDF file.