note 18062 deleted from function.sprintf by felipe
| From: | felipe@php.net | Date: | Fri, 04 Jan 2008 01:41:44 +0000 |
| Subject: | note 18062 deleted from function.sprintf by felipe | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-134749@lists.php.net to get a copy of this message | ||
Note Submitter: radu dot rendec at ines dot ro
Reason: 5
----
The 'e' format specifier is not documented. However, it seems to work, but without showing
the exponential part of the number.
This is a function to get the scientific representation of a number:
function sci($x, $d=-1) {
$e=floor(log10($x));
$x*=pow(10,-$e);
$fmt=($d>=0)?".".$d:"";
$e=($e>=0)?"+".sprintf("%02d",$e):"-".sprintf("%02d",-$e);
return sprintf("%".$fmt."fe%s",$x,$e);
}
It takes the number as the first parameter and the precision as the second. The precision is
optional. The default precision for the 'f' format specifier is used if no precision is
specified.