ID:               30764
 Updated by:       [EMAIL PROTECTED]
 Reported By:      php at arantius dot com
-Status:           Open
+Status:           Feedback
 Bug Type:         Output Control
 Operating System: Windows XP
 PHP Version:      4.3.9
 New Comment:

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));
?>




Previous Comments:
------------------------------------------------------------------------

[2004-11-11 21:06:19] 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.


------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=30764&edit=1

Reply via email to