php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #21913 formatting for sci notation
Submitted: 2003-01-27 19:30 UTC Modified: 2012-09-22 09:34 UTC
From: sprice at wisc dot edu Assigned: nikic (profile)
Status: Closed Package: *General Issues
PHP Version: 4.3.0 OS: Mac OS X.2.3
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: sprice at wisc dot edu
New email:
PHP Version: OS:

 

 [2003-01-27 19:30 UTC] sprice at wisc dot edu
I humbly request that scientific notation formatting (ex. 7.16e-11) is added to the function sprintf(). Currently I am using a function supplied by another user:

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); 
}


and can be found in the comments of this page:
http://www.php.net/manual/en/function.sprintf.php

This function seems to be working fine for the time being, but this seems like somethine many other people would use and an addition to PHP itself would be better.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-09-22 09:34 UTC] nikic@php.net
-Status: Open +Status: Closed -Package: Feature/Change Request +Package: *General Issues -Assigned To: +Assigned To: nikic
 [2012-09-22 09:34 UTC] nikic@php.net
Closing as scientific notation is already available via %e, %E (and %g, %G for mixed).
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sat Jul 26 21:00:02 2025 UTC