ID: 30764 Updated by: [EMAIL PROTECTED] Reported By: php at arantius dot com -Status: No Feedback +Status: Bogus Bug Type: Output Control Operating System: Windows XP PHP Version: 4.3.9 New Comment:
Can't reproduce with 5.x and see the manual about formatting numbers. Previous Comments: ------------------------------------------------------------------------ [2008-08-20 07:32:00] 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% ------------------------------------------------------------------------ [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] [EMAIL PROTECTED] 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