Tuesday, November 10, 2009

long number problem in php 5.2.6

I found an interesting problem with long numbers using php 5.2.6. Yah, the current version of php is 5.3 but some hosting server still using older versions.

my problem was the following:


$integer = 2304200000;
echo $integer; //outputs 2.3042E+09

$float = (float)100000; //float
echo $float; //outputs 1E+05


this gives many weird results in calculation. I have faced this problem and this bug has eaten up a lot of time.So, I am others time regarding the big number problem in php 5.2.6.

If you use number_format or sprintf then you will get the number as aspected.


$integer = 2304200000;
$int = number_format($integer, 0, '.', '');
echo $int; //outputs 2304200000 as expected

$float = (float)100000 //float;
$float = number_format($float, 2, '.', '');
echo $float; //outputs 100000.00 as expected