|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2004-12-18 12:18 UTC] patrick at ilmander dot com
Description:
------------
Printing a variable with %.2f should output the number with 2 decimals. After upgrading to 4.3.10 it now outputs 3 decimals. %.1f outputs with 2 decimals and I haven't figured out how to print out just 1 decimal (%.1f doesn't work), so I'm treating this as a bug.
Reproduce code:
---------------
printf("%.2f", $member[score] / $member[votes]);
Expected result:
----------------
1.23
Actual result:
--------------
1.234
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Oct 29 14:00:01 2025 UTC |
This works fine here: $ php-4.3dev -r 'echo sprintf("%.2f", 42.1231213123);' 42.12I'm sorry, I should have given you more details. The problem doesn't seem to be printf() itself, but where I used it. I was using the following code: "Rating: <b><?=printf("%.2f", $rating)?></b>" which worked fine in 4.3.4, but when we upgraded to 4.3.10 it produced the stated error. I've updated all my code to "Rating: <b><?php printf("%.2f", $rating)?></b>" which works fine. I probably shouldn't have used printf() inside a <?= ?> in the first place, but it worked fine in 4.3.4 and not in 4.3.10, that's why I reported it as a bug. Sorry for wasting your time. // Patrick