php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #24030 sprintf with negative floating point type leaves null in string
Submitted: 2003-06-05 00:39 UTC Modified: 2003-06-05 00:56 UTC
From: prgallier at yahoo dot com Assigned:
Status: Closed Package: Strings related
PHP Version: 4.3.2 OS: Linux 2.4.20
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: prgallier at yahoo dot com
New email:
PHP Version: OS:

 

 [2003-06-05 00:39 UTC] prgallier at yahoo dot com
Using sprintf with a floating point value for a negative number leaves a null character in the string, such as:
$num = sprintf("%0.1f", -12.5);

$num will contain the following characters within the actual string when printing out:
0x45 0x31 0x32 0x2E 0x35 0x00

This does not occur with non-negative numbers.

Try the following for realtime example:
<?php
$num = sprintf("%0.1f", 12.5);
echo "Positive Num: $num<br>\n";
$num = sprintf("%0.1f", -12.5);
echo "Negative Num: $num<br>\n";
?>

This is apparently an old bug that's been reintroduced in version 4.3.2.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-06-05 00:56 UTC] sniper@php.net
Already fixed in CVS.

 [2003-09-24 10:49 UTC] tyler at nas dot net
A temporary work around:
"%1.1f" doesn't seem to print the nulls like "%0.1f" does.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Apr 30 00:01:30 2024 UTC