PHP Float
In this chapter you will learn:
- What is float number
- PHP Float Literal
- Example - floating-point arithmetic
- Example - Calculate the area of a circle of given radius
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// j av a 2 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/*from j av a2 s . c o m*/
$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//from jav a 2s .com
$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.
Next chapter...
What you will learn in the next chapter: