Bug #78562 [Opn]: money_format() returns string with incorrect number

From: Date: Thu, 19 Sep 2019 09:17:49 +0000
Subject: Bug #78562 [Opn]: money_format() returns string with incorrect number
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-222827@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=78562&edit=1

 ID:                 78562
 Updated by:         nikic@php.net
 Reported by:        candace dot camarillo at vacasa dot com
 Summary:            money_format() returns string with incorrect number
 Status:             Open
 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:

...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.


Previous Comments:
------------------------------------------------------------------------
[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.

------------------------------------------------------------------------
[2019-09-18 21:24:09] candace dot camarillo at vacasa dot com

However, hard-coding this number into the money_format() method causes the error, too.

------------------------------------------------------------------------
[2019-09-18 21:22:44] candace dot camarillo at vacasa dot com

Our production code used some math to come up with this number.  It just so happened that when we
upgrading our project to PHP7, a test failed that expected the correct number.  So I only found this
particular number by chance.

------------------------------------------------------------------------


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)

« previous php.bugs (#222827) next »