How to print scientific notation numbers in custom format using PHP? -


i have set of scientific notation numbers (x), shown in column 1 in table below. trying print numbers in custom format shown in column 3 using php. how can so? tried printf("%.0e", $x); , print sprintf("%.0e", $x);, got result shown in column 2.

please me solve problem.

scientific notation number

actually output generated ncbi blast server using cgi script. after many trials, found new method solve problem. but, still surprised... whether there solution using perl/cgi.

<?php function efmt($hsp_evalue) {     $x = (float)sprintf("%.1e", $hsp_evalue);     if (preg_match("/e-/i", $x)) {         $y = explode("e-", $x);         if ($y[1] < 10) return round($y[0]) . "e-0" . $y[1];         else return round($y[0]) . "e-" . $y[1];     } else {         if (preg_match("/\./", $x)) {             if ($x * 1000 < 1) return round($x * 10000) . "e-04";             else return $x;         } else             return $x . ".0";     } }  print efmt("9.58544"); // output: 9.6 ?> 

Comments

Popular posts from this blog

Sort a complex associative array in PHP -

vb.net - How to ignore if a cell is empty nothing -

recursion - Can every recursive algorithm be improved with dynamic programming? -