PHP Number

A number is a mathematical object and one of the datatypes which is used to count, measure and calculation. In computer programming, a number is very important datatype. PHP has two types of numbers, Integers & Floating point numbers. PHP allows us to perform different operations on numbers for example comparing numbers, operation on series etc.

To round off floating point number

It is possible to round off floating point number through round() function.

Example

<?php 
$x = round(13.30);
echo $x;
?> 

This will produce following result

13

To compare two approximately equal floating point numbers

It is possible to compare two approximately equal floating point numbers through abs() function.

Example

<?php 
$x = 25.0000001;
$y = 25.0000000;
if(abs($x-$y)<0.00001){
echo "$x and $y are approximately equal.";
?> 

This will produce following result

25.0000001 and 25.0000000 are approximately equal.

To apply a single code to a range of integers

It is possible to apply a single code to a range of integers using loops.

Example

<?php 
$x = 2;
$y = 8;
echo "List of even numbers between 2 and 8 is:"
for ($z = $x; $z <= $y; $z++){
echo $z/n;
?> 

This will produce following result

List of even numbers between 2 and 8 is:
2
4
6
8

To search for the number having minimum value in an array of unordered numbers

It is possible to search for the number having minimum value in an array of unordered numbers using sort() function.

Example

<?php 
$x = array(100,1,50,25,10);
$y = sort($x);
echo "Minimum value in the array is $y[0].";
?> 

This will produce following result

Minimum value in the array is 1.

To search for the number having maximum value in an array of unordered numbers

It is possible to search for the number having maximum value in an array of unordered numbers using sort() function.

Example

<?php 
$x = array(100,1,50,25,10);
$y = sort($x);
echo "Maximum value in the array is $y[sizeof($y)-1].";
?> 

This will produce following result

Maximum value in the array is 100.


 
SHARE THIS IF YOU LIKE!
submit to reddit

SUBSCRIBE FOR LATEST UPDATES
HAVE WE CONNECTED ON FACEBOOK?
TOP TUTORIALSTOP CODE EXAMPLESTOP LIVE DEMOLINKSSTAY CONNECTED
HTML Tutorial
HTML5 Tutorial
Bootstrap3 Tutorial
Javascript Tutorial
TypeScript Tutorial
AngularJS Tutorial
CSharp Tutorial
PHP Tutorial
Developer Tools
Javascript
AngularJS
Google MAP API V3
ASP.NET
Javascript
AngularJS
Google MAP API V3
Contact Us
Advertise with Us
Privacy Policy
Disclaimer
Stay connected. We actually like you. If you want to get up to the minute updates, then connect with us on your fav below.
 
Twitter   Linkedin   Facebook   Google+    RSS   Pinterest
 
Protected by Copyscape Original Content Checker
 
 
Copyright ©2017 www.techstrikers.com Unauthorized reproduction/replication of any part of this site is prohibited.