#26952 [Opn->Csd]: printf()'s implementation of length/precision is inconsistent w/ other language
| From: | dave@php.net | Date: | Mon, 30 Aug 2004 09:39:33 +0000 |
| Subject: | #26952 [Opn->Csd]: printf()'s implementation of length/precision is inconsistent w/ other language | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-65452@lists.php.net to get a copy of this message | ||
ID: 26952
Updated by: dave@php.net
Reported By: pluggz24 at yahoo dot com
-Status: Open
+Status: Closed
Bug Type: Feature/Change Request
Operating System: windows
PHP Version: Irrelevant
New Comment:
Thank you for your bug report. This issue has already been fixed
in the latest released version of PHP, which you can download at
http://www.php.net/downloads.php
This has been fixed as of 4.3.7 and 5.0.0.
Previous Comments:
------------------------------------------------------------------------
[2004-01-17 22:34:10] pluggz24 at yahoo dot com
Description:
------------
from the first user comment on http://us2.php.net/printf,
(not written by me):
I'm not sure if it is a feature or a bug :) but it's definately a
gotcha! The length.precison in a printf float is different from any
other language's printf. The difference is outlined below in a small
program written in C, PERL, and PHP using the printf function:
In C:
...>cat pf-test.c
main() {
printf("12345678901234567890\n");
printf("%09.2f\n",22.0/7.0);
}
...>gcc pf-test.c -o pf-test
...>./pf-test
12345678901234567890
000003.14
NOTE: Nine *total* displayed chars, two behind the decimal
Now PERL:
...>cat pf-test.pl
#!/usr/bin/perl
printf("12345678901234567890\n");
printf("%09.2f\n",22.0/7.0);
...>perl pf-test.pl
12345678901234567890
000003.14
NOTE: *Identical* to 'C' (and awk, and ...)
Now PHP:
...>cat pf-test.php
<?php
printf("123456789012340567890\n");
printf("%09.2f\n",22.0/7.0);
?>
...>php -q pf-test.php
123456789012340567890
000000003.14
NOTE: Nine digits before the decimal, the decimal, and two places
after.
This tends to hide in proportional fonts, but can cause wierd alignment
issues and gaps, particularly if you are using pre-formatted mono-spaced
text.
Reproduce code:
---------------
<?php
printf("123456789012340567890\n");
printf("%09.2f\n",22.0/7.0);
?>
Expected result:
----------------
12345678901234567890
000003.14
Actual result:
--------------
123456789012340567890
000000003.14
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=26952&edit=1