note 48880 added to function.sprintf

From: Date: Mon, 10 Jan 2005 18:58:11 +0000
Subject: note 48880 added to function.sprintf
Groups: php.notes 
Request: Send a blank email to php-notes+get-83047@lists.php.net to get a copy of this message
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)); ?> ---- Manual Page -- http://www.php.net/manual/en/function.sprintf.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+48880 Delete -- http://master.php.net/manage/user-notes.php?action=delete+48880&report=yes Reason: bad code -- http://master.php.net/manage/user-notes.php?action=delete+48880&report=yes&reason=bad+code Reason: spam -- http://master.php.net/manage/user-notes.php?action=delete+48880&report=yes&reason=spam Reason: useless example -- http://master.php.net/manage/user-notes.php?action=delete+48880&report=yes&reason=useless+example Reason: contains commercial links -- http://master.php.net/manage/user-notes.php?action=delete+48880&report=yes&reason=contains+commercial+links Reason: useless note -- http://master.php.net/manage/user-notes.php?action=delete+48880&report=yes&reason=useless+note Reject -- http://master.php.net/manage/user-notes.php?action=reject+48880&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#83047) next »