Bug #78562 [Opn]: money_format() returns string with incorrect number
Edit report at https://bugs.php.net/bug.php?id=78562&edit=1
ID: 78562
Updated by: cmb@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:
Works as expected on <https://3v4l.org/NiIHL>. *Might*
be a musl
issue.
Anyhow, I would not use floating point values for monetary
calculations.
Previous Comments:
------------------------------------------------------------------------
[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.
------------------------------------------------------------------------
[2019-09-18 20:56:37] requinix@php.net
Are you hardcoding 2040.33 into your script? Or did you do some math to get that number?
------------------------------------------------------------------------
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)