note 48880 deleted from function.sprintf by cmb

From: Date: Sun, 02 Dec 2018 13:01:13 +0000
Subject: note 48880 deleted from function.sprintf by cmb
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-209834@lists.php.net to get a copy of this message
Note Submitter: timo at frenay dot net ---- Note that the documentation is unclear about the details of the sign specifier. First of all, the character for this is "+". Also note that the following does NOT print "+00.00" as you might expect: <?php printf('%+02.2f', 0); ?> The sign is included in the width. This can't be solved by increasing the width: <?php printf('%+03.2f', 0); ?> This will put the padding 0 before the sign. Here is a possible solution: <?php $value = 0; printf('%s%02.2f', ($value < 0) ? '-' : '+', abs($value)); ?>

« previous php.notes (#209834) next »