note 21954 deleted from function.sprintf by nikic
| From: | nikic@php.net | Date: | Sat, 22 Sep 2012 09:35:51 +0000 |
| Subject: | note 21954 deleted from function.sprintf by nikic | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-190957@lists.php.net to get a copy of this message | ||
Note Submitter: shgyn at binabakti dot or dot id
----
Previously submitted sci() function to get scientific representation of a number is not working with
0 and negative numbers. So, here is the modified version:
function sci($x, $d=-1) {
$min=($x<0)?"-":"";
$x=abs($x);
$e=floor(($x!=0)?log10($x):0);
$x*=pow(10,-$e);
$fmt=($d>=0)?".".$d:"";
$e=($e>=0)?"+".sprintf("%02d",$e):"-".sprintf("%02d",-$e);
return sprintf("$min%".$fmt."fe%s",$x,$e);
}