php.net |  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
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: abajolet at toiletoine dot net
New email:
PHP Version: OS:

 

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

I just discover strange behavior of printf/sprintf :

This code :
<?php
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
4
48
-0.20<invisible character there -> mozilla displays a square>
6
0

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 \
            --enable-inline-optimization

Best regards,
Antoine Bajolet

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-05-31 09:01 UTC] derick@php.net
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 http://snaps.php.net/.
 
In case this was a documentation problem, the fix will show up soon at
http://www.php.net/manual/.

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