0

Sorry for not using the correct terminology, the fact is I don't know what you'd call this sort of number so it's making it incredibly difficult to Google.

I want to multiply two numbers together and get the result back as just numbers, but I keep getting a string looking like this: float(8.6135096694932E+15). I need to export this in an XML file so I need a string containing just the numbers not this weird response I am currently getting.

Here is a very simple example:

var_dump(2005489*4294967297)
//Actual Result: float(8.6135096694932E+15)
//Desired Result: 8613509669493233

My question is simply. How can I multiple those two numbers together and get the desired result listed above?

For a bit more context of what i'm trying to do: I am given an ID, in this instance "2005489" and I need to generate a new ID based on a fermat numbering system, which basically seems to mean that it must be multiplied by "4294967297", I do not fully understand why since I am interacting with third party software. It seems simple enough, but I need to actually be able to print the string "8613509669493233" in an XML file, not the weird response i'm actually getting.

EDIT 2: Found another solution, very simple:

number_format($number, 0, '', '');

Found here: Convert exponential to a whole number in PHP

EDIT: This has been marked as duplicate of this: Arithmetic with Arbitrarily Large Integers in PHP

However I cannot see how that offers a solution. The only example is:

gmp_strval(gmp_init($n, 10), 2);

However this does not offer any resolution, here is an example:

$number = (string)(2005489*4294967297);
$response = gmp_strval(gmp_init($number, 10), 2);
var_dump($response);
//0

Not using (string) results in:

gmp_init(): Unable to convert variable to GMP - wrong type

Community
  • 1
  • 1
John Mellor
  • 2,351
  • 8
  • 45
  • 79

0 Answers0