|  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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
From: abajolet at toiletoine dot net
New email:
PHP Version: OS:


 [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