# [PATCH] number_format bug fix (29538)

- Thread: https://externals.io/message/24414
- Original archive: https://news-web.php.net/php.internals/24414
- Started by Matt W on 2006-07-16T10:36:53+00:00
- Messages: 1
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #24414 — Matt W — 2006-07-16T10:36:53+00:00

URL: https://externals.io/message/24414#24414

Hi,

Here's patches I mentioned a week ago for bug #29538.  I happened to notice
it while trying to enhance the functionality of `number_format()`.  It's also
mentioned at the end of bug #28228.  Where

number_format(1234, 2, '', ',')

returns 123,400 instead of the expected 1,23400

Happens when decimal places is > 0 with an empty decimal separator.  There's
a test with that criteria, but the thousands separator is also empty, which
hides the bug.

I also made some small optimizations -- removing a `strlen()`, etc. -- hope
they're OK.  Another possible(?) problem in _php_math_number_format was that
if no decimal point was found (with dec > 0), s-- would lose the right-most
integer digit.  That's why it's decremented in the if (dp) {  } block now.
(dp should exist, I guess, if dec > 0, but the check is already there in
case. :-))

Finally, I changed the proto, if that's OK, to match what's in the manual,
and be closer to the variable names...  And "separator" was spelled wrong
anyway. ;-)

I don't know if it's too late to fix 4.4.3, but I have the diff for it too.

http://realplain.com/php/number_format_bug29538.diff
http://realplain.com/php/number_format_bug29538_5_2.diff
http://realplain.com/php/number_format_bug29538_4_4.diff

And a test file:
http://realplain.com/php/bug29538.phpt


Thanks,
Matt
