php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #29620 money_format treats 0.00*-1 strangely
Submitted: 2004-08-11 20:56 UTC Modified: 2004-08-12 00:06 UTC
From: benjcarson at digitaljunkies dot ca Assigned:
Status: Not a bug Package: Strings related
PHP Version: 5CVS-2004-08-11 (dev) OS: Linux
Private report: No CVE-ID: None
 [2004-08-11 20:56 UTC] benjcarson at digitaljunkies dot ca
Description:
------------
When using the format '%(n' (i.e. represent negative numbers in parenthesis), money_format still prints out a negative sign when its second parameter is 0.00*-1.   It works fine for the following values, however:

-0.00
-0
0*-1
-1*0
-1*0.00
-1.00*0

(Note: echo(0.00*-1) prints out -0.)

Interestingly, using gcc-3.3.4 and glibc-2.3.2, the following fails in a similar fashion:

strfmon(buf, sizeof(buf), "%(n", atof("-0.00"));
/* buf = "-0.00" */

double val = 0.00 * -1;
strfmon(buf, sizeof(buf), "%(n", val);
/* buf = "-0.00" */

double val = -1*0.00;
strfmon(buf, sizeof(buf), "%(n", val);
/* buf = "-0.00" */

It appears it might have something to do with strfmon()'s handling of 'negative zero', except money_format() works correctly for values where strfmon() fails (e.g. -1*0.00).

Reproduce code:
---------------
echo money_format("%(n", 0.00*-1) . "\n";

Expected result:
----------------
0.00

or even

(0.00)

Actual result:
--------------
-0.00

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-08-12 00:06 UTC] iliaa@php.net
Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system is not the
appropriate forum for asking support questions. 

Thank you for your interest in PHP.

the money_format() function returns the exact same value as 
that of strfmon() without any modifications. Any unexpected 
output is likely to be a fault in glibc. 
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 10:01:28 2024 UTC