|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #23921 printf/sprintf problem with %f and negative numbers
Submitted: 2003-05-31 08:42 UTC Modified: 2003-05-31 09:01 UTC
From: abajolet at toiletoine dot net Assigned:
Status: Closed Package: Strings related
PHP Version: 4.3.2 OS: Linux Mandrake 8.1
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
Solve the problem:
46 - 24 = ?
Subscribe to this entry?

 [2003-05-31 08:42 UTC] abajolet at toiletoine dot net

I just discover strange behavior of printf/sprintf :

This code :
printf('%01.2f',0.2); print '<br>';
$test = sprintf('%01.2f',0.2);
print strlen($test).'<br>';
print ord(substr($test,-1)).'<br>';

printf('%01.2f',-0.2); print '<br>';
$test = sprintf('%01.2f',-0.2);
print strlen($test).'<br>';
print ord(substr($test,-1)).'<br>';

Give me :
-0.20<invisible character there -> mozilla displays a square>

It seems that the bug #6192 is back !

With php 4.3.0, this bug did not appear, with exactly the same config but php itself.

Compile options, both 4.3.0 and 4.3.2 :

./configure --with-apxs2=/usr/local/apache2/bin/apxs \
            --with-config-file-path=/etc \
            --with-ming \
            --with-ldap \
            --with-mysql \
            --with-pgsql \
            --with-gd \
            --with-jpeg-dir=../jpeg-6b \
            --with-png-dir=../libpng-1.2.2 \
            --with-freetype-dir=../freetype-2.1.0 \
            --with-t1lib \
            --enable-bcmath \
            --enable-calendar \
            --enable-trans-sid \
            --with-mcrypt \
            --with-mhash \
            --with-regex=php \
            --with-zlib \
            --enable-ftp \
            --with-openssl \
            --with-snmp \
            --enable-ucd-snmp-hack \
            --enable-sockets \
            --enable-track-vars \
            --enable-magic-quotes \
            --enable-xslt \
            --with-xslt-sablot \
            --with-iconv=/usr/local \
            --enable-sigchild \

Best regards,
Antoine Bajolet


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2003-05-31 09:01 UTC]
This bug has been fixed in CVS.

In case this was a PHP problem, snapshots of the sources are packaged
every three hours; this change will be in the next snapshot. You can
grab the snapshot at
In case this was a documentation problem, the fix will show up soon at

In case this was a website problem, the change will show
up on the site and on the mirror sites in short time.
Thank you for the report, and for helping us make PHP better.
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Sun Oct 01 13:01:24 2023 UTC