Floating Point Numbers PHP Essential Training

Floating Point Numbers PHP Essential Training

PHP

Floating Point Numbers PHP Essential Training

Welcome to another effective lesson in our PHP essential training. In this lesson we're gonna learn the what are the capabilities of floating point numbers PHP Essential Training. So far we learn the various string functions in our last lesson. Like the string the floating number has extra features and functions.
The floating number is nothing but a number with a decimal points. It is used for gives the accurate values of the result. For example divide 4 by 3 is 1.3333333333333 but in normal number it gives only 1. So we use float to give the exact 1.3333333333333. Like us we told earlier in this essential training PHP will identify the variable type as itself, so we don't mention it is a float variable. Let's see what we can do with the floating point numbers.
<?php
// This is a general float number example.
$var1 = 3.14;
echo "Floating Numbers: " . $var1; "<br />"
?>
Floating Point Numbers PHP Essential Training
// The Round function is used to round the value at certain decimal points. It stops the continuing float numbers.
echo "Round: " . round($var1, 1) . "<br />";
Floating Point Numbers PHP Essential Training
// Ceiling is the is another Floating Point Numbers PHP Essential Training function for round the given float value to its next whole number like the following.
echo "Ceiling: " . ceil($var1) . "<br />";
Floating Point Numbers PHP Essential Training
// Floor is the opposite function of the Ceil. It gives the previous whole number of the given decimal point value.
echo "Floor: " . floor($var1) . "<br />";
Floating Point Numbers PHP Essential Training
// abs is a function to give the absolute value of the given expression.
echo "Absolute: " . abs(0-300) . "<br />";
Floating Point Numbers PHP Essential Training
// Here we get exponential value for the given power value. We use base and exp values for this.
echo "Exponential: " . pow(2, 2) . "<br />";
Floating Point Numbers PHP Essential Training
// We have a square root function to get the root of the given value.
echo "Square Root: " . sqrt(100) . "<br />";
Floating Point Numbers PHP Essential Training
// Modulo is an operator in division operation. But it is used for get the remaining values.
echo "Modulo: " . fmod(20, 7) . "<br />";
Floating Point Numbers PHP Essential Training
// It is used for generates the random values in any of the regions.
echo "Random (any): " . rand() . "<br />";
Floating Point Numbers PHP Essential Training
// This is also a random generator but it generates within the given minimum and maximum range.
echo "Random (min, max): " . rand(1, 100) . "<br />";
Floating Point Numbers PHP Essential Training
This will gives you a clear idea about the various number functions in PHP. To know more about the String Functions go to the previous Number Functions PHP Essential Training
Download the source Code of Floating Point Numbers PHP Essential Training from here.

Leave a Reply