i need help
i need help

Reputation: 2386

convert bytes to GB in php

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.

Upvotes: 0

Views: 4387

Answers (1)

Fragsworth
Fragsworth

Reputation: 35497

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

Example:

$a = gmp_init("2487234329784238974238974")
$result = gmp_div($a, 2)

Upvotes: 1

Related Questions