Search This Blog

  • ()
  • ()
Show more

PHP Tutorial - PHP Integer

Integers hold whole numbers, either positive or negative, such as 1, -20, 12345,etc. The limit of integer is between -2147483647 and 2147483...

Integers hold whole numbers, either positive or negative, such as 1, -20, 12345,etc. The limit of integer is between -2147483647 and 2147483647. The integer numbers outside the range are automatically converted to floats.

The following code adds two integer values together in PHP.


<?php /* w w w. j a v a 2 s.com*/
$var1 = 5;
$var2 = 2;
$answer = $var1 + $var2;
print "$var1 plus $var2 equals $answer.";
?>


The code above generates the following result.


PHP integer Literal


We may specify integers in hexadecimal (base 16) or octal (base 8). The octal number system only uses the digits 0 to 7. hexadecimal uses 0 to 9, then A, B, C, D, E, and F.

To specify number in octal, we must precede it with a 0 (zero).


<?PHP
$octalnum = 06331;
print $octalnum;
?>


The code above generates the following result.


Hexadecimal


To specify a number in hexadecimal, precede it with 0x.


<?PHP
$hexnum = 0x44;
print $hexnum;
?>


The code above generates the following result.


Example - Integer literal


The following code uses different integer literals to assign value to integers.


<?PHP/* w w w .j a v a2 s . c o m*/
$a = 1234; # decimal number
print($a);
print("n");
$a = -123; # a negative number
print($a);
print("n");
$a = 0123; # octal number (equivalent to 83 decimal)
print($a);
print("n");
$a = 0x12; # hexadecimal number (equivalent to 18 decimal)
print($a);
print("n");
?>


The code above generates the following result.







Float


Floats hold fractional numbers as well as very large integer numbers, such as 4.2, 1.00000001, and 123123123123000.

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 w w. ja va 2 s . c om*/
$a = 1.234;
print ($a);
print ("n");
$a = 1.2e3;
print ($a);
?>


The code above generates the following result.







Example - floating-point arithmetic


Here are some examples of floating-point arithmetic:


<?PHP/*from w w w . j a v a2 s .com*/
$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 - Calculate the area of a circle of given radius


Calculate the area of a circle of given radius


<?php/* w w w . j a va2 s. co 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.O

COMMENTS

BLOGGER: 1
Loading...
Name

apple,2,Article,14,At home,13,Author,14,Beauty,1,Biography,2,blackberry,1,Business,6,Cars,5,Celebrity,13,conspiraci,15,Fashion,5,galaxy,1,Gallery,1,Games,11,google,1,Hair,1,Health amp; Fitness,2,Histori,11,Home,169,HOSTING,27,HTML,7,imac,1,Image,1,iphone,1,Itcyber,7,Kuran,31,Lajme,34,Life amp; Love,1,Makeup amp; Skincare,1,mobile,5,monitor,1,Movies,2,News,5,No category,5,Photography,6,PHP,30,Poezi,24,POEZI amp; TEKSTE,2,Post,14,PROGRAMMIM,46,Relationships,1,review,6,samsung,1,Seo,7,Softvare,4,Sport,5,Sports,7,Stars,5,Tag,7,Tags,7,Tech,30,Teknologji,37,THEMES,3,Tutorials,191,Video,47,Videos,4,Vip News,2,Webhosting,67,WordPress,7,World,13,
ltr
item
Cr337: PHP Tutorial - PHP Integer
PHP Tutorial - PHP Integer
http://www.java2s.com/Tutorials/PHPImage/myResult/P/PHP_INTEGER__F27A55998059EFB4607E.PNG
Cr337
https://cr337.blogspot.com/2016/03/php-tutorial-php-integer.html
https://cr337.blogspot.com/
http://cr337.blogspot.com/
http://cr337.blogspot.com/2016/03/php-tutorial-php-integer.html
true
5516280490839897951
UTF-8
Loaded All Posts Not found any posts VIEW ALL Readmore Reply Cancel reply Delete By Home PAGES POSTS View All RECOMMENDED FOR YOU LABEL ARCHIVE SEARCH ALL POSTS Not found any post match with your request Back Home Sunday Monday Tuesday Wednesday Thursday Friday Saturday Sun Mon Tue Wed Thu Fri Sat January February March April May June July August September October November December Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec just now 1 minute ago $$1$$ minutes ago 1 hour ago $$1$$ hours ago Yesterday $$1$$ days ago $$1$$ weeks ago more than 5 weeks ago Followers Follow THIS CONTENT IS PREMIUM Please share to unlock Copy All Code Select All Code All codes were copied to your clipboard Can not copy the codes / texts, please press [CTRL]+[C] (or CMD+C with Mac) to copy