March 18, 2009

Integer and floating point number in Php

Integers in php can be declared as decimal, octal or hexadecimal.
To declare an octal precede the number with zero. (0)
To declare an hexadecimal precede the number with 0x.

The following is the declaration of integer types.
$decimal=786; //decimal positive
$decimalNegative=-12345; //decimal negative
$octalNumber=0123; //octal number
$hexNumber=0xA1B; //hexadecimal


The Integer size can be determined using the constant PHP_INT_SIZE.
The maximum size of the Integer can be determined using the constant PHP_INT_MAX.

The maximum value of Integer is platform dependent.

If Php encounters a value that is beyond integer type then it treats the value as float.

Some declaration of floating point numbers are,

$float1 = 1.234;
$floatExp1 = 4.5e7;
$floatExp2 = 10E-9;

No comments:

Post a Comment