Questions And Answers

More Tutorials

PHP Outputting large integers

On 32-bits systems, integers larger than PHP_INT_MAX are automatically converted to float. Outputting these as integer values (i.e. non-scientific notation) can be done with printf, using the float representation, as illustrated below:

foreach ([1, 2, 3, 4, 5, 6, 9, 12] as $p) {
 $i = pow(1024, $p);
 printf("pow(1024, %d) > (%7s) %20s %38.0F", $p, gettype($i), $i, $i);
echo " ", $i, "\n";


pow(1024, 1) integer 1024 1024 1024
pow(1024, 2) integer 1048576 1048576 1048576
pow(1024, 3) integer 1073741824 1073741824 1073741824
pow(1024, 4) double 1099511627776 1099511627776 1099511627776
pow(1024, 5) double 1.1258999068426E+15 1125899906842624
pow(1024, 6) double 1.1529215046068E+18 1152921504606846976
pow(1024, 9) double 1.2379400392854E+27 1237940039285380274899124224
pow(1024, 12) double 1.3292279957849E+36 1329227995784915872903807060280344576

While this looks nice, in this contrived example the numbers can all be represented as a binary number since they
are all powers of 1024 (and thus 2). See for example:

$n = pow(10, 27);
printf("%s %.0F\n", $n, $n);


1.0E+27 1000000000000000013287555072


In this page (written and validated by ) you learned about PHP Outputting large integers . What's Next? If you are interested in completing PHP tutorial, your next topic will be learning about: PHP Constants.

Incorrect info or code snippet? We take very seriously the accuracy of the information provided on our website. We also make sure to test all snippets and examples provided for each section. If you find any incorrect information, please send us an email about the issue:

Share On:

Mockstacks was launched to help beginners learn programming languages; the site is optimized with no Ads as, Ads might slow down the performance. We also don't track any personal information; we also don't collect any kind of data unless the user provided us a corrected information. Almost all examples have been tested. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. By using, you agree to have read and accepted our terms of use, cookies and privacy policy.