ZF-6561: Zend_Currency::toCurrency(): negative values errors


I did not have the time to debug this bug, but I think it also depends on Zend_Locale_Format::toNumber().

I have tried the following:

require_once 'Zend/Currency.php';
$currency = new Zend_Currency(null, 'de_DE');

Zend_Debug::dump($currency->toCurrency(-74.95, array('currency' => 'EUR', 'precision' => 4))); // returns -74

$currency = new Zend_Currency(null, 'en_US');
Zend_Debug::dump($currency->toCurrency(-74.95, array('currency' => 'USD', 'precision' => 4))); // returns $-(74.9500)

As you can see, for de_DE with EUR, the precision part completely misses, and I don't know why there are brackets for en_US with USD, because it doesn't look valid. I would think of a return value like "$-74.9500". If I'm wrong, please let me know.


The same problem with 1.8:

Here is what I see:

require_once 'Zend/Currency.php';

$currency = new Zend_Currency('USD', 'en_US');
Zend_Debug::dump($currency->toCurrency(-74.95)); // returns  -($74.95))

$currency = new Zend_Currency('USD', 'ru_RU');
Zend_Debug::dump($currency->toCurrency(-74.95)); // returns -74.95

It seems, something wrong with formatting negative values..

According to unicode and google, the brackets are correct for negative currency values.

Can you provide some links? I haven't found anything by a search with Google. I think I have to argue with those links ...

I don't think the formatted value: -($74.95)) with double brackets at the end is correct value, so as for ru_RU there is no currency symbol is displayed at all - just negative value.

Fixed with r15607

I have only found out, that brackets are used for USD when it is used for accounting, but then you have to left the "-" in front of the brackets. For prices it seems to be -$74. Thomas, can you post those links where you have found, how to write those currency values?

Even when I try "-150 GBP in USD" with Google, the result is "-239.62500 U.S. dollars" - no brackets ...

I can not reproduce your problem.

My Testcode:

$currency = new Zend_Currency('USD');


My output:

string '$ 100,00' (length=9)
string '-$ 100,00' (length=10)

Which is is the output given by the CLDR formatting rules.

Which version of ZF have you used for testing? In your first comment, you have pointed out that negative currency values in USD should have brackets and you have reverted your statement - and I'm confused now :)

My first comment is from 15.May. This issue is marked as fixed per 16.May for the next minor release.

I tested with the next minor release as mentioned above with the results outlined above.