php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #28228 number_format function bug
Submitted: 2004-04-30 02:49 UTC Modified: 2004-12-14 01:39 UTC
From: bichinhoverde at spwinternet dot com dot br Assigned: iliaa (profile)
Status: Closed Package: Math related
PHP Version: 4CVS, 5CVS (2004-12-12) OS: *
Private report: No CVE-ID: None
 [2004-04-30 02:49 UTC] bichinhoverde at spwinternet dot com dot br
Description:
------------
When I put an empty string '' as the decimal point in the number_format function, it uses the dot '.' as decimal point.

The function works well for the thousands separator.

Reproduce code:
---------------
print number_format(1234.5678, 2, '', '');


Expected result:
----------------
123457

Actual result:
--------------
1234.57

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-04-30 03:22 UTC] bichinhoverde at spwinternet dot com dot br
I was expecting the same behavior for the decimal point and the thousands separator. If you write:

number_format(1234.5678, 2, 'a', 'b');

It outputs:

1b234a57

Is it understandable? Does it matter?

If you specify no thousands separator, it displays the number without it. But the same is not true for the decimal point.

These two lines have the same result:
number_format(1234.5678, 2, '', '');
number_format(1234.5678, 2, '.', '');

It shouldn't be, IMHO.

Now, why would I use fractional numbers without the decial point? Because I must print bank codes that have currency values in them. They use fixed point (2 decimal places) instead of floating point. So, $ 1234,55 will be 123455 in the bank code. Got it?
 [2004-04-30 03:34 UTC] bichinhoverde at spwinternet dot com dot br
Just in case someone finds this "feature report", here is a work around:

number_format(1234.5678*100,0,'','');

It prints "123457" as I wanted.
 [2004-04-30 09:19 UTC] derick@php.net
It's not a feature, it's a bug of course.
 [2004-04-30 15:26 UTC] iliaa@php.net
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.


 [2004-09-23 17:04 UTC] mark at quarella dot co dot uk
I have just discovered that:
  number_format(11.99, 2, FALSE, ',')
which used to display
  11.99
now displays
  1,199

I'm not sure whether FALSE ought to be supported as a "use the default" rather than equivalent to the empty string, but surely at worst this should give:
  1199

My preference, for what it's worth, is that FALSE should take the default ('.'), but '' should work better than it does?

[I only have 4.3.8 to test against but no mention of this is made in the 4.3.9 release notes]
 [2004-09-23 17:08 UTC] mark at quarella dot co dot uk
To be a bit clearer than my previous comment:
  number_format(1234.56, 2, '', ',')
should result in 
  1,23456
not
  123,456
as it does now.

Ideally
  number_format(1234.56, 2, FALSE, ',')
would give
  1,234.56
but
  1,23456
would be better than the current behaviour.
 [2004-09-23 19:43 UTC] bichinhoverde at spwinternet dot com dot br
Well, according to the documentation, dec_point and thousands_sep should be both string. I wouldn't know what to expect when I put a boolean value in ther.

But, regarding:

print number_format(1234.56, 2, '', ',');

it really outputs 123,456 when it should output 1,23456. I tested it on 4.3.8 on windows. I thinks it is another "feature" ;)
 [2004-12-12 23:46 UTC] sniper@php.net
This is not fixed correctly. See also bug #29538

 [2004-12-14 01:39 UTC] iliaa@php.net
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 12:01:29 2024 UTC