Zend Framework

Zend_Currency::toCurrency(): negative values errors

Details

  • Type: Bug Bug
  • Status: Resolved Resolved
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: 1.8.0
  • Fix Version/s: 1.9.0
  • Component/s: Zend_Currency, Zend_Locale
  • Labels:
    None

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:

Unable to find source-code formatter for language: php. Available languages are: javascript, sql, xhtml, actionscript, none, html, xml, java
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.

Activity

Hide
Maxim Savenko added a comment - - edited

The same problem with 1.8:

Here is what I see:

Unable to find source-code formatter for language: php. Available languages are: javascript, sql, xhtml, actionscript, none, html, xml, java
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..

Show
Maxim Savenko added a comment - - edited The same problem with 1.8: Here is what I see:
Unable to find source-code formatter for language: php. Available languages are: javascript, sql, xhtml, actionscript, none, html, xml, java
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..
Hide
Thomas Weidner added a comment -

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

Show
Thomas Weidner added a comment - According to unicode and google, the brackets are correct for negative currency values.
Hide
Dennis Becker added a comment -

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

Show
Dennis Becker added a comment - Can you provide some links? I haven't found anything by a search with Google. I think I have to argue with those links ...
Hide
Maxim Savenko added a comment -

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.

Show
Maxim Savenko added a comment - 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.
Hide
Thomas Weidner added a comment -

Fixed with r15607

Show
Thomas Weidner added a comment - Fixed with r15607
Hide
Dennis Becker added a comment -

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

Show
Dennis Becker added a comment - 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 ...
Hide
Thomas Weidner added a comment -

I can not reproduce your problem.

My Testcode:

$currency = new Zend_Currency('USD');

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

My output:

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

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

Show
Thomas Weidner added a comment - I can not reproduce your problem. My Testcode:
$currency = new Zend_Currency('USD');

var_dump($currency->toCurrency(100));
var_dump($currency->toCurrency(-100));
My output:
string '$ 100,00' (length=9)
string '-$ 100,00' (length=10)
Which is is the output given by the CLDR formatting rules.
Hide
Dennis Becker added a comment -

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

Show
Dennis Becker added a comment - 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
Hide
Thomas Weidner added a comment -

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.

Show
Thomas Weidner added a comment - 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.

People

Vote (3)
Watch (2)

Dates

  • Created:
    Updated:
    Resolved: