#30764 [Com]: printf + zero fill + negative number = extra null character on windows xp
| From: | babu at ransysbios dot com | Date: | Wed, 20 Aug 2008 07:32:00 +0000 |
| Subject: | #30764 [Com]: printf + zero fill + negative number = extra null character on windows xp | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-128245@lists.php.net to get a copy of this message | ||
ID: 30764
Comment by: babu at ransysbios dot com
Reported By: php at arantius dot com
Status: No Feedback
Bug Type: Output Control
Operating System: Windows XP
PHP Version: 4.3.9
New Comment:
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%
Previous Comments:
------------------------------------------------------------------------
[2005-01-28 01:00:04] 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".
------------------------------------------------------------------------
[2005-01-19 03:25:12] 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));
?>
------------------------------------------------------------------------
[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