Bug #78562 [Nab]: money_format() returns string with incorrect number
Edit report at https://bugs.php.net/bug.php?id=78562&edit=1
ID: 78562
User updated by: candace dot camarillo at vacasa dot com
Reported by: candace dot camarillo at vacasa dot com
Summary: money_format() returns string with incorrect number
Status: Not a bug
Type: Bug
Package: *Math Functions
Operating System: Apline Linux 3.8
PHP Version: 7.2.22
Block user comment: N
Private report: N
New Comment:
Thanks so much for looking at this!
Previous Comments:
------------------------------------------------------------------------
[2019-09-19 14:29:41] requinix@php.net
So it's a libc/strfmon bug.
The intl extension can do this with NumberFormatter::formatCurrency().
https://www.php.net/manual/en/numberformatter.formatcurrency.php
Or if you don't care about currency symbols, number_format() or even sprintf().
------------------------------------------------------------------------
[2019-09-19 09:17:49] nikic@php.net
...and this is why money_format() is deprecated in PHP 7.4. You're at the mercy of your libc
implementation, and most don't exactly put much effort into strfmon() functionality, that
nobody outside of PHP uses anymore.
------------------------------------------------------------------------
[2019-09-19 08:29:47] cmb@php.net
Works as expected on <https://3v4l.org/NiIHL>. *Might*
be a musl
issue.
Anyhow, I would not use floating point values for monetary
calculations.
------------------------------------------------------------------------
[2019-09-18 21:33:18] candace dot camarillo at vacasa dot com
Adding round(,2) to the number gives the same problem:
echo money_format('%i', round(2040.33, 2))
// '2040.32'
------------------------------------------------------------------------
[2019-09-18 21:28:25] requinix@php.net
Try adding round(,2) to the number before giving it to money_format.
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
https://bugs.php.net/bug.php?id=78562
--
Edit this bug report at https://bugs.php.net/bug.php?id=78562&edit=1
Thread (10 messages)