0

I am trying to a do a big calculation for example:

$a = 50000 * 1000000000000000000;

the result its 5.0E+22 in php

how can I convert it or print it as "50000000000000000000000" as string, cause it's not possible in int?

Anand Siddharth
  • 967
  • 1
  • 9
  • 30
  • 2
    Possible duplicate of [PHP how to convert number exponential number to string?](https://stackoverflow.com/questions/43510301/php-how-to-convert-number-exponential-number-to-string) – John Karasinski Jun 25 '18 at 17:17

1 Answers1

3

This number is actually too large for an integer representation in PHP and converting to a float won't get the precision for this number. When doing math that requires huge numbers or accurate precision, it's best to use bc math with strings.

echo bcmul("50000", "1000000000000000000");
// prints "50000000000000000000000"
Devon Bessemer
  • 34,461
  • 9
  • 69
  • 95