Hello friends, this is my first tutorial of PHP and I am starting with the Numbers. As for any programming language the Numbers are the basics so
I am thinking that starting PHP is better with numbers. Today I will discuss Number format in PHP with easy example. I will discuss with you the various ways in which we can use numbers and also give you examples by using which you can easily manipulates with Numbers.
First thing to take into consideration is that every PHP code is written within:
For Working with Numbers we need variables. So let's create some variables in PHP :
<?php Your Code Comes Here ?>
For Working with Numbers we need variables. So let's create some variables in PHP :
<?php $var1=3; $var2=4; ?>Now lets look at some basic operations that we can perform with numbers in PHP :
Arithmetic Operation : <?php echo ((1+3+$var1)*$var2)/2-5; ?> += Opeation : <?php $var2+=4; ?> -= Operation : <?php $var2-=4; ?> *=& Operation : <?php $var2*=4; ?> /= Operation : <?php $var2/=4; ?> Increment: <?php $var2++; ?> Decrement: <?php $var2--; ?>Now Lets work with some floating point numbers. I will show you how you can perform some basic operations with Floating point numbers in PHP :
Declaring Floating point Variable: <?php $var3=3.14; echo 4/3; ?> Printing Floating point Variable: <?php echo $var3; ?> Round: <?php echo round($var3); ?> Ceiling Value: <?php echo ceil($var3); ?> Floor Value: <?php echo floor($var3); ?> Absolute Value: <?php echo abs(0-200); ?> Power: <?php echo pow($var3,2); ?> Square Root: <?php echo sqrt($var3); ?> Random Value: <?php echo rand(); ?> Random Min-Max: <?php echo rand(1,100); ?> Modulus: <?php echo fmod(20,7); ?>
0 comments:
Post a Comment
Note: only a member of this blog may post a comment.