php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #32518 number_format returns -0,00
Submitted: 2005-03-31 16:44 UTC Modified: 2005-04-03 18:04 UTC
Votes:9
Avg. Score:4.7 ± 0.9
Reproduced:9 of 9 (100.0%)
Same Version:1 (11.1%)
Same OS:6 (66.7%)
From: php at mijav dot dk Assigned:
Status: Wont fix Package: Math related
PHP Version: 4CVS, 5CVS (2005-03-31) OS: *
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
MUST BE VALID
Solve the problem:
10 + 18 = ?
Subscribe to this entry?

 
 [2005-03-31 16:44 UTC] php at mijav dot dk
Description:
------------
Tthe number -0,00 is non-existent and inconsistent, pointed out in a duplicate bug report, and therefore the output is jibberish.

If you do a number_format(round($foo,2), 2, ",", "."); then the output will be correct/as expected. This is also why number_format should be considered buggy. If number_format rounds before formatting, it should be consistent: -0,00 isn't consistent since -0,505 gets rounded to -0,51.

Please re-evaluate the situation. The output -0,00 is not useful.

Please note that our production server uses 4.3.8, but the Changelog reports nothing about a fix, and the previous bug report was marked Bogus.

Reproduce code:
---------------
<?
echo number_format(-0.0012499999998, 2, ",", ".");
?>

Expected result:
----------------
0,00

Actual result:
--------------
-0,00

Patches

Add a Patch

Pull Requests

Add a Pull Request

 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 21:01:27 2024 UTC