PHP Float
Description
Floats hold fractional numbers as well as very large integer numbers. Floating-point numbers are called real numbers or just floats.
Float Literal
We may also specify an exponent with your float, i.e., 3.14159e4 is equal to 31415.9.
<?PHP/* w ww .j a v a2 s .c o m*/
$a = 1.234;
print ($a);
print ("\n");
$a = 1.2e3;
print ($a);
?>
The code above generates the following result.
Example
Here are some examples of floating-point arithmetic:
<?PHP/* w ww . ja va 2 s . c om*/
$a = 1.132324;
print($a);
$b = $a + 1.9;
print($b);
$b = $a + 1.0;
print($b);
$c = 1.1e15;
print($c);
$d = (0.1+0.7) * 10;
print($d);
?>
The code above generates the following result.
Example 2
Calculate the area of a circle of given radius
<?php/* w w w .jav a 2 s .c o m*/
$radius = 2.0;
$pi = 3.14159;
$area = $pi * $radius * $radius;
echo("radius = ");
echo($radius);
echo("<BR>area = ");
echo($area);
?>
The code above generates the following result.