Issues

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

Issue Type: Bug Created: 2009-05-06T09:00:01.000+0000 Last Updated: 2009-06-09T05:23:31.000+0000 Status: Resolved Fix version(s): - 1.9.0 (31/Jul/09)

Reporter: Dennis Becker (radhad) Assignee: Thomas Weidner (thomas) Tags: - Zend_Currency

  • Zend_Locale

Related issues: Attachments:

Description

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:

<pre class="highlight">
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.

Comments

Posted by Maxim Savenko (maxix) on 2009-05-08T04:07:01.000+0000

The same problem with 1.8:

Here is what I see:

<pre class="highlight">
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..

Posted by Thomas Weidner (thomas) on 2009-05-15T10:25:27.000+0000

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

Posted by Dennis Becker (radhad) on 2009-05-15T23:52:26.000+0000

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

Posted by Maxim Savenko (maxix) on 2009-05-16T05:46:43.000+0000

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.

Posted by Thomas Weidner (thomas) on 2009-05-16T07:33:38.000+0000

Fixed with r15607

Posted by Dennis Becker (radhad) on 2009-06-09T00:22:46.000+0000

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 ...

Posted by Thomas Weidner (thomas) on 2009-06-09T04:08:41.000+0000

I can not reproduce your problem.

My Testcode:

<pre class="highlight">
$currency = new Zend_Currency('USD');

var_dump($currency->toCurrency(100));
var_dump($currency->toCurrency(-100));

My output:

<pre class="highlight">
string '$ 100,00' (length=9)
string '-$ 100,00' (length=10)

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

Posted by Dennis Becker (radhad) on 2009-06-09T04:12:14.000+0000

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 :)

Posted by Thomas Weidner (thomas) on 2009-06-09T05:23:31.000+0000

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.

Have you found an issue?

See the Overview section for more details.

Copyright

© 2006-2016 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.

Contacts