|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #78292 NumberFormatter procedural functions don't work
Submitted: 2019-07-15 09:52 UTC Modified: 2019-07-15 10:55 UTC
From: delboy1978uk at gmail dot com Assigned:
Status: Not a bug Package: intl (PECL)
PHP Version: 7.1.30 OS: any
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
Solve the problem:
49 - 3 = ?
Subscribe to this entry?

 [2019-07-15 09:52 UTC] delboy1978uk at gmail dot com
When using numfmt_create() and numfmt_currency(), PHP flakes out and gives us some number in Scientific Notation, instead of formatting like US currency.

Look here 

Test script:

$fmt = numfmt_create('en_US', NumberFormatter::TYPE_CURRENCY );
echo numfmt_format_currency($fmt, 32.00, "USD")."\n";

$fmt = new NumberFormatter( 'en_US', NumberFormatter::CURRENCY );
echo $fmt->formatCurrency(32.00, "USD")."\n";

/* output as follows


Expected result:

Actual result:


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2019-07-15 10:00 UTC] matthew at matthewsetter dot com
In addition to the bug description provided, I have the following example, using the procedural functions:

$fmt = numfmt_create('en_US', NumberFormatter::DECIMAL);
echo numfmt_format_currency($fmt, 32.00, "EUR")."\n";

I would expect that this would return 32,00, however, it returns 32. I've used a number of ISO 4217 currency codes (specifically USD, EUR, AUD, GBP) but the output remains the same. It's worth noting that if the float value provided to numfmt_format_currency contains a fractional part, in addition to the integral part, then the number formats as expected. 

Environment Details: PHP 7.3.6 / macOS 10.14.5.
 [2019-07-15 10:10 UTC]
-Summary: NumberFormatter procedural functions dont work +Summary: NumberFormatter procedural functions don't work -Status: Open +Status: Verified -Package: Unknown/Other Function +Package: intl
 [2019-07-15 10:16 UTC] delboy1978uk at gmail dot com
-Status: Verified +Status: Closed
 [2019-07-15 10:16 UTC] delboy1978uk at gmail dot com
closing, as it turns out the dev was using TYPE_CURRENCY and not just CURRENCY. It works after the change
 [2019-07-15 10:21 UTC]
From the docs:

`These styles are used by the numfmt_create() to define the type of the formatter.` 

... NumberFormatter:CURRENCY ...

`These constants define how the numbers are parsed or formatted. They should be used as arguments to numfmt_format() and numfmt_parse().`: 

... NumberFormatter::TYPE_CURRENCY ...

Wrong parameter choosen here. :)


To the problem in the comments with decimal

Original code:


$fmt = numfmt_create('en_US', NumberFormatter::DECIMAL);
echo numfmt_format_currency($fmt, 32.00, "EUR")."\n";

Fixed code:


$fmt = numfmt_create('en_US', NumberFormatter::DECIMAL);
numfmt_set_attribute($fmt, NumberFormatter::MIN_FRACTION_DIGITS, 2);
echo numfmt_format_currency($fmt, 32.00, "EUR")."\n";
 [2019-07-15 10:55 UTC]
-Status: Closed +Status: Not a bug
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Mon Jul 06 21:01:04 2020 UTC