views:

387

answers:

2

Hi there,

I want to convert bytes to GB. value= 8587321344

So it should be 8587321344/1024/1024/1024

But whenever I go to divide, the value is wrong... If I cast it into integer, it will be limited to 2147....

Can't find any type cast to long data type...

Funny enough...

How to perform this calculation to show correct output...

The maximum value depends on the system. 32 bit systems have a maximum signed integer range of -2147483648 to 2147483647. So for example on such a system, intval('1000000000000') will return 2147483647. The maximum signed integer value for 64 bit systems is 9223372036854775807.

A: 

Look at the GNU Multiple Precision library for arbitrary size integers in PHP.

Example:

$a = gmp_init("2487234329784238974238974")
$result = gmp_div($a, 2)
Fragsworth
hmm.. whole page go blank when I use gmp...
i need help
Sounds like you probably don't have gmp, try php.net/bcmath instead.
TML
+3  A: 
 8587321344/1024/1024/1024

is wrong.. correct is below..

 8587321344/(1024*1024*1024)
Akash Kava
or 8587321344/1073741824
Eineki
oh yeah thanks, I am lazy, let the cpu does the job :)
Akash Kava
both calculations do exactly the same mathematicly.
Femaref