note 18062 added to function.sprintf

From: Date: Wed, 09 Jan 2002 11:49:49 +0000
Subject: note 18062 added to function.sprintf
Groups: php.notes 
Request: Send a blank email to php-notes+get-24572@lists.php.net to get a copy of this message
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. -- http://www.php.net/manual/en/function.sprintf.php http://master.php.net/manage/user-notes.php?action=edit+18062 http://master.php.net/manage/user-notes.php?action=delete+18062 http://master.php.net/manage/user-notes.php?action=reject+18062

« previous php.notes (#24572) next »