Sunday, January 29, 2012

How can I increase the size of my integer variable in PHP?


I need to store a huge number in a PHP variable (it's for a programming contest if you're wondering why). However, if the number is too big, it gets displayed as 6.2995416979471E+77 . Is there a way to store that huge number in PHP?


3 comments:

  1. integers have a limited size of 32 or 64bit, depending on your architecture.
    floats can store values of any size, but are imprecise.

    If you want to work with giant, precise numbers, use strings and the BC Math extension.

    ReplyDelete
  2. $bigNumber = 1234567890; // etc
    echo number_format($bigNumber, 0);

    ReplyDelete
  3. Have you tried PHP's BCMath arbitrary precision functions? They use strings to represent numbers.

    ReplyDelete