Bug #55290 [Com]: \NumberFormatter::parseCurrency() fails

From: Date: Sat, 04 Oct 2014 22:21:33 +0000
Subject: Bug #55290 [Com]: \NumberFormatter::parseCurrency() fails
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-187853@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=55290&edit=1

 ID:                 55290
 Comment by:         hannes dot forsgard at gmail dot com
 Reported by:        franssen dot roland at gmail dot com
 Summary:            \NumberFormatter::parseCurrency() fails
 Status:             Open
 Type:               Bug
 Package:            I18N and L10N related
 Operating System:   Linux
 PHP Version:        5.3.6 - 5.3.8
 Block user comment: N
 Private report:     N

 New Comment:

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


Previous Comments:
------------------------------------------------------------------------
[2013-01-03 01:46:39] 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.

------------------------------------------------------------------------
[2013-01-02 10:26:56] 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-02 08:35:24] 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";

------------------------------------------------------------------------
[2012-10-23 12:41:26] 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

------------------------------------------------------------------------
[2012-05-05 09:15:37] 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

------------------------------------------------------------------------


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=55290


--
Edit this bug report at https://bugs.php.net/bug.php?id=55290&edit=1


Thread (11 messages)

« previous php.bugs (#187853) next »