0

Scientific Notation Bug in PHP

Posted (Updated ) in PHP

There is a bug in some version of PHP causing large integers to print in scientific notation. Here’s how to replicate:

<?php
	$i = 6395360031312041;
 
	echo $i; //Outputs: 6.39536003131E+15

There is a quick and easy fix for this – simply number_format your integer whilst printing like so:

<?php
	$i = 6395360031312041;
 
	echo number_format($i, 0, '.', ''); //Outputs: 6395360031312041

This issue has been fixed in the latest version of PHP 5.2 (as of the time of writing that’s PHP 5.2.12).