Check out the Latest Articles:

A while ago I was experimenting on how long does it take for a plain page to load on my local server. The output I was receiving was so small that it was being displayed in exponential form rather than decimal something like this 2.8848648071289E-5.
Well, to be honest I hate numbers with exponents because they are so confusing and secondly because they look ugly.

A quick Google for converting exponents to decimal didn’t work out for me, so I started out writing my own function using regular expressions except for the information that PHP automatically converts numbers with high precision into exponential form. “Strings!” was the first thing that flicked my mind reading that ad the second was “Regular Expressions”

So I made my own function to convert exponential into decimal, and the good thing is.. it works. Here is the trick

$total_time = 2.8848648071289E-5;

echo exp2dec($total_time);

function exp2dec($number) {
	preg_match('/(.*)E-(.*)/', str_replace(".", "", $number), $matches);
	$num = "0.";
	while ($matches[2] > 0) {
		$num .= "0";
		$matches[2]--;
	}
	return $num . $matches[1];
}

Related posts:

  1. Sanitizing Variables in PHP without Regular Expressions
  2. Using Operators in PHP – Learn PHP in 7 Days – Day #2
  3. PHP Syntax, Variables, Echo Statement – Learn PHP in 7 Days – Day #1
  4. Simple Database Class for PHP
  5. How to display your twitter follower count using PHP


  1. It‘s quite in here! Why not leave a response?