NumberFormatter::parseCurrency
is a thin wrapper around the ICU library function unum_parseDoubleCurrency
(see source).
The ICU library function is restrictive in that it will only parse strings that would result from its dual function unum_formatDoubleCurrency
. The format is driven by the Unicode locale data, which specifies a non-breaking space between the currency value and the numeric value. Evidently the earlier version of the library accepted other whitespace characters.
In short, you can't make NumberFormatter::parseCurrency
accept spaces. However, Zend_Currency
should also output non-breaking spaces by default:
$currency = new Zend_Currency(array(
'currency' => 'EUR',
'value' => 88.22,
), 'de_DE');
var_dump(
strval($currency), // 88,22 €
strpos($currency, "\x20"), // false
strpos($currency, "\xc2\xa0") // 5
);
The question is which part of your application is outputting a space and how you address it. You mention it's part of your form, so maybe you could look at having the form return the currency and the value as separate fields, so that you don't have to worry about parsing the number. If the user is entering the string "88,22 €" themselves, you could potentially run in to more problems than just the whitespace issue. Having said that, the workaround you mention (replacing \x20
with \xc2\xa0
) is the only way to address that if you want to use NumberFormatter
.