Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to handle a value that is bigger than 16 digits in PHP?

Tags:

php

I am calling a method using SOAPclient and the method (remote external SOAP web service) is returning me a 19 digit number. I have no control over what is being returned. When i print the value of this number only the first 16 digits are accurate. I have tried type casting, GMP etc. But looks like the full 19 digits is already lost when php assigns the value to the variable based on the result from the web service call. So there is no way to retrieve the value.

$client = new SoapClient($sccSystemWSDL);
try{
    $sessionID = $client->logonUser($adminUser,$passWord);
}

On a 64 bit machine I did not have this issue. But now I have to run this on a 32 bit machine and no luck till now.

like image 273
user1996611 Avatar asked Feb 04 '13 09:02

user1996611


People also ask

What is the limit of PHP integer value?

PHP Integers An integer data type is a non-decimal number between -2147483648 and 2147483647 in 32 bit systems, and between -9223372036854775808 and 9223372036854775807 in 64 bit systems. A value greater (or lower) than this, will be stored as float, because it exceeds the limit of an integer.

How do you count the length of a number in PHP?

$numlength = (int)(log($num+1, 10)+1); Or for a math solution that counts the digits in positive OR negative numbers: $numlength = ($num>=0) ? (int)(log($num+1, 10)+1) : (int)(log(1-$num, 10)+1); But the strlen solution is just about as fast in PHP.

How do I echo an integer in PHP?

echo (int) ( (0.1+0.7) * 10 ); // echoes 7!


1 Answers

Use BCMath it allows the numbers to be processed as strings instead of integers so does not have size limit. Also you should increase the precision directive to a larger number say 20 or so.

like image 152
cryptic ツ Avatar answered Oct 06 '22 03:10

cryptic ツ