php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #55290 \NumberFormatter::parseCurrency() fails
Submitted: 2011-07-26 20:23 UTC Modified: 2021-02-01 15:40 UTC
Votes:12
Avg. Score:4.7 ± 0.6
Reproduced:11 of 11 (100.0%)
Same Version:8 (72.7%)
Same OS:8 (72.7%)
From: franssen dot roland at gmail dot com Assigned: cmb (profile)
Status: Closed Package: I18N and L10N related
PHP Version: 5.3.6 - 5.3.8 OS: Linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: franssen dot roland at gmail dot com
New email:
PHP Version: OS:

 

 [2011-07-26 20:23 UTC] franssen dot roland at gmail dot com
Description:
------------
Hi,

The example code at http://nl2.php.net/manual/en/numberformatter.parsecurrency.php doesn't seem to work for me.

This is perhaps also related to bug #54163 (?)

---

version        1.1.0
ICU version    4.4.1

Directive              Local Value    Master Value
intl.default_locale    no value	      no value
intl.error_level       0              0

Test script:
---------------
<?php
$fmt = numfmt_create( 'de_DE', NumberFormatter::CURRENCY );
$num = "1.234.567,89 $";
echo "We have ".numfmt_parse_currency($fmt, $num, $curr)." in $curr\n";
echo \PHP_EOL;

$fmt = new NumberFormatter( 'de_DE', NumberFormatter::CURRENCY );
$num = "1.234.567,89 $";
echo "We have ".$fmt->parseCurrency($num, $curr)." in $curr\n";
die;

Expected result:
----------------
We have 1234567.89 in USD
We have 1234567.89 in USD

Actual result:
--------------
We have <FALSE> in <NULL>
We have <FALSE> in <NULL>

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-07-28 07:04 UTC] franssen dot roland at gmail dot com
Same code does works on PHP 5.2.17 (Linux)

version 	1.0.3
ICU version 	3.6
 [2011-08-23 18:09 UTC] franssen dot roland at gmail dot com
-Operating System: Ubuntu 11.04 +Operating System: Linux -PHP Version: 5.3.6 +PHP Version: 5.3.6 - 5.3.8
 [2011-08-23 18:09 UTC] franssen dot roland at gmail dot com
Still fails in 5.3.8...
However it does seems to work when parsing in locale en[_US], e.g. $1 returns float(1) ("USD"). Didn't spot any other locales that work (mostly tested european locales; netherlands, germany, french)
 [2011-11-09 04:56 UTC] johnlinton at mailinator dot net
Seeing the same issue except I am using PHP 5.3.8 as a fcgi module under apache 2.2 on Windows 7.
 [2012-05-05 09:15 UTC] franssen dot roland at gmail dot com
Still fails in PHP 5.4RC9...

version 		1.1.0
ICU version 		4.4.2
ICU Data version 	4.4.2
 [2012-10-23 12:41 UTC] mail at michael-weimann dot eu
Doesn't work in PHP 5.3.10

intl version 1.1.0
ICU version 4.8.1.1
ICU Data version 4.8.1
 [2013-01-02 08:35 UTC] fkrautwald at gmail dot com
I don’t believe it is a bug. The problem is the example code. It errors when you 
copy it. There is some invisible invalid character between the space and the 
dollar sign, I believe. Try to replace the space character and the dollar sign in 
the `$num` variable, typing it.

You can also check it with this code:

$fmt = new \NumberFormatter('de_DE', \NumberFormatter::CURRENCY);
$num = "1.234.567,89 $";
print "We have ".$fmt->parseCurrency($num, $curr)." in $curr\n";
 [2013-01-02 10:26 UTC] franssen dot roland at gmail dot com
Tested the example code once more (copy-paste) on PHP 5.4.10 (ICU version 4.4.1, ICU Data version 4.4.0.1).

It still fails :') Also re-typing the code didnt help;

<?php
$fmt = numfmt_create('de_DE', NumberFormatter::CURRENCY);
$num = '1.234.567,89 $';
$curr = null;
echo 'We have ' . numfmt_parse_currency($fmt, $num, $curr) . ' in ' . $curr . PHP_EOL;

echo PHP_EOL;

$fmt = new NumberFormatter('de_DE', NumberFormatter::CURRENCY);
$num = '1.234.567,89 $';
$curr = null;
echo 'We have ' . $fmt->parseCurrency($num, $curr) . ' in ' . $curr . PHP_EOL;
 [2013-01-03 01:46 UTC] fkrautwald at gmail dot com
That is odd that the example code had a hidden character which created an error, 
and removing it fixed the example on PHP 5.4.10 on Windows 7.

I am aware that this is filed as a bug under Linux, but what a remarkable 
coincidence.
 [2014-10-04 22:21 UTC] hannes dot forsgard at gmail dot com
Example

<?php
$fmt = new NumberFormatter( 'de_DE', NumberFormatter::CURRENCY );
$num = "1.234.567,89 $";
echo "We have ".$fmt->parseCurrency($num, $curr)." in $curr\n";
?>

rewritten as

<?php
$fmt = new NumberFormatter( 'de_DE', NumberFormatter::CURRENCY );
$num = "1.234.567,89\xc2\xa0$";
echo "We have ".$fmt->parseCurrency($num, $curr)." in $curr\n";
?>

works for me (php 5.5.16 on Ubuntu 12.04).

See http://stackoverflow.com/a/16509321
 [2021-02-01 15:40 UTC] cmb@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: cmb
 [2021-02-01 15:40 UTC] cmb@php.net
This issue has been fixed long ago[1].

[1] <http://git.php.net/?p=doc/en.git;a=commit;h=f7af074111bf3c6fe840d5cbb4a76e3909c15d25>
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Mar 19 07:01:29 2024 UTC