php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #30764 printf + zero fill + negative number = extra null character on windows xp
Submitted: 2004-11-11 21:06 UTC Modified: 2008-08-20 08:00 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: php at arantius dot com Assigned:
Status: Not a bug Package: Output Control
PHP Version: 4.3.9 OS: Windows XP
Private report: No CVE-ID: None
 [2004-11-11 21:06 UTC] php at arantius dot com
Description:
------------
When using printf, zero fill, floats, and negative numbers, PHP 4.3.9 on Windows XP Pro SP1 generates null characters at the end of the number that should not be there.
Passing a negative number, i.e. -1, into the format string "%0.2f" will give an invalid result, i.e. "-1.00[NULL]" where [NULL] is the 0th byte.

Reproduce code:
---------------
<?
printf("%0.2f<br />", 1.51555);     //ok
printf("%0.2f<br />", -1.51555);    //broken
printf("%0.2f<br />", -1);          //broken
printf("%.2f<br />", -1.5);         //ok
printf("%.2f<br />", -1.51555);     //ok
printf("%0.2f<br />", 1.51555);     //ok
?>

Expected result:
----------------
I expect "-1.00" or appropriately rounded values with no trailing null bytes.

Actual result:
--------------
Cannot paste output, it is truncated at the first null byte.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-01-19 03:25 UTC] sniper@php.net
Please try using this CVS snapshot:

  http://snaps.php.net/php4-STABLE-latest.tar.gz
 
For Windows:
 
  http://snaps.php.net/win32/php4-win32-STABLE-latest.zip


And try this script with the PHP CLI binary:

<?php
var_dump(sprintf("%0.2f", 1.51555));     
var_dump(sprintf("%0.2f", -1.51555));
var_dump(sprintf("%0.2f", -1));
var_dump(sprintf("%.2f", -1.5));
var_dump(sprintf("%.2f", -1.51555));
var_dump(sprintf("%0.2f", 1.51555));
?>


 [2005-01-28 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 [2008-08-20 07:32 UTC] babu at ransysbios dot com
i am displaying percentage like 3.5%, 44.45% , 55.44%, 66.1 now i want dispaly this result in to 3.50% and 66.1%
 [2008-08-20 08:00 UTC] pajoye@php.net
Can't reproduce with 5.x and see the manual about formatting numbers.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Apr 20 00:01:27 2024 UTC