|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[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> PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Oct 25 12:00:01 2025 UTC |
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)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";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;