note 17341 added to function.sprintf
| From: | anqmb at php2 dot chek dot com | Date: | Wed, 05 Dec 2001 09:51:15 +0000 |
| Subject: | note 17341 added to function.sprintf | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-21626@lists.php.net to get a copy of this message | ||
Watch out the mysterious rounding rule.
<?php
$a = 4.5;
$b = sprintf("%d",$a);
$c = 4.5;
$d = sprintf("%.0f",$c);
$e = 0.45;
$f = sprintf("%.1f",$e);
print ("$b,$d,$f\n");
?>
The code above prints "4,5,0.5".
(Perl version prints "4,4,0.5".)
--
http://www.php.net/manual/en/function.sprintf.php
http://master.php.net/manage/user-notes.php?action=edit+17341
http://master.php.net/manage/user-notes.php?action=delete+17341
http://master.php.net/manage/user-notes.php?action=reject+17341