php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #70056 NumberFormatter::formatCurrency() ignores CURRENCY_SYMBOL
Submitted: 2015-07-12 18:05 UTC Modified: 2015-07-15 23:03 UTC
From: benjamin dot morel at gmail dot com Assigned: cmb (profile)
Status: Not a bug Package: intl (PECL)
PHP Version: 5.6.11 OS: CentOS 7
Private report: No CVE-ID: None
 [2015-07-12 18:05 UTC] benjamin dot morel at gmail dot com
Description:
------------
I think this is related to bug #65572.

CURRENCY_SYMBOL is taken into account when using format(), but not when using formatCurrency(). See example below.

Test script:
---------------
$formatter = new \NumberFormatter('en_US', NumberFormatter::CURRENCY);
$formatter->setSymbol(NumberFormatter::CURRENCY_SYMBOL, '@');

echo $formatter->format(1.2), PHP_EOL;
echo $formatter->formatCurrency(1.2, 'USD');

Expected result:
----------------
@1.20
@1.20

Actual result:
--------------
@1.20
$1.20

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-07-12 18:11 UTC] cmb@php.net
-Status: Open +Status: Not a bug -Assigned To: +Assigned To: cmb
 [2015-07-12 18:11 UTC] cmb@php.net
The ::formatCurrency() method expects the $currency parameter to
be:

| The 3-letter ISO 4217 currency code indicating the currency to
| use.

Exactly that is what's happening.
 [2015-07-15 22:00 UTC] benjamin dot morel at gmail dot com
Indeed, and that's exactly what I'm passing to the method.
But setSymbol() should overwrite the symbol, whatever the currency, shouldn't it?
 [2015-07-15 23:03 UTC] cmb@php.net
> But setSymbol() should overwrite the symbol, whatever the
> currency, shouldn't it?

IMHO, that wouldn't make sense. ::setSymbol() sets a default, but
the $currency parameter of ::formatCurrency() overrides it. That
appears to be pretty common, cf. mb_internal_encoding() and
mb_substr(), for instance. If you want to use the default, don't
set the $currency parameter, i.e. use ::format().
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Dec 22 05:01:30 2024 UTC