Req #27916 [Opn->Csd]: Add support for %g (significant digits) format to printf functions

From: Date: Sat, 01 Nov 2014 22:31:36 +0000
Subject: Req #27916 [Opn->Csd]: Add support for %g (significant digits) format to printf functions
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-188404@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=27916&edit=1 ID: 27916 Updated by: requinix@php.net Reported by: tcarter at noggin dot com dot au Summary: Add support for %g (significant digits) format to printf functions -Status: Open +Status: Closed Type: Feature/Change Request -Package: Feature/Change Request +Package: *General Issues Operating System: Linux PHP Version: Irrelevant -Assigned To: +Assigned To: requinix Block user comment: N Private report: N New Comment: Added in 5.2.1 during "Changed double-to-string utilities to use BSD implementation" https://github.com/php/php-src/commit/4d44a5b71dd74ea81d988f7f1e0ff8025bef5617#diff-e02d8864bd088660ded278bc073c2674R245 printf('%1$.4e %1$.4f %1$.4g', 123.456); // 1.234e+2 123.4560 123.5 Previous Comments: ------------------------------------------------------------------------ [2004-04-07 22:36:27] tcarter at noggin dot com dot au Description: ------------ PHP's sprintf() (and other printf type functions) do not provide any method to specify the number of significant digits to be output, only field lengths and precision. The glibc printf (3) man page lists a 'g' conversion specifier which behaves the same as 'd' but interprets the precision field as the number of significant digits to output rather than the number of digits to place after the decimal point. Since PHP doesn't appear to have any existing built-in mechanism for formatting a value to a specified number of significant digits, I think that support for this should be added to sprintf(). ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=27916&edit=1

« previous php.bugs (#188404) next »