Search code examples
phpscientific-notation

how can i convert 5.0E+22 to string in php


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?


Solution

  • 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"