Bug #78562 [Opn->Fbk]: money_format() returns string with incorrect number
Edit report at https://bugs.php.net/bug.php?id=78562&edit=1
ID: 78562
Updated by: requinix@php.net
Reported by: candace dot camarillo at vacasa dot com
Summary: money_format() returns string with incorrect number
-Status: Open
+Status: Feedback
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:
Try adding round(,2) to the number before giving it to money_format.
Previous Comments:
------------------------------------------------------------------------
[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?
------------------------------------------------------------------------
[2019-09-18 19:42:09] candace dot camarillo at vacasa dot com
Description:
------------
---
From manual page: https://php.net/function.money-format
---
Running money_format() with the number 2040.33 returns a string with 2040.32. Other numbers seem to
work. I have not iterated through others to determine which cause the problem. Playing with locale
and other flags makes no impact on the problem.
Test script:
---------------
echo money_format('%i', 2040.33); // returns '2040.32'
Expected result:
----------------
'2040.33'
Actual result:
--------------
'2040.32'
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=78562&edit=1
Thread (10 messages)