note 21954 added to function.sprintf
| From: | shgyn at binabakti dot or dot id | Date: | Sat, 01 Jun 2002 11:57:06 +0000 |
| Subject: | note 21954 added to function.sprintf | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-31320@lists.php.net to get a copy of this message | ||
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);
}
--
http://www.php.net/manual/en/function.sprintf.php
http://master.php.net/manage/user-notes.php?action=edit+21954
http://master.php.net/manage/user-notes.php?action=delete+21954
http://master.php.net/manage/user-notes.php?action=reject+21954