Issues

ZF-10549: Zend_Currency with exchange service results in incorrect currency-symbol when adding currencies

Issue Type: Bug Created: 2010-10-11T09:33:13.000+0000 Last Updated: 2012-11-20T21:37:45.000+0000 Status: Open Fix version(s): Reporter: Micha Verboeket (mverboeket) Assignee: None Tags: - Zend_Currency

Related issues: Attachments:

Description

<pre class="highlight">
//Precondition: the locale is set to 'nl_NL', which has EUR as currency

//original currency+value (USD0.0)
$currency = new Zend_Currency(
    array(
        'value'    => 0.0,
        'currency' => 'USD',
    )
);
$currency->setService(Zend_Registry::get('ZFCustom_Currency_ExchangeService')); 


$currency2 = new Zend_Currency(
    array(
        'value'    => 250,
        'currency' => 'EUR',
    )
);
$currency->add($currency2);//EUR250 exchanged to USD347.08

echo $currency.'<br></br>'; //prints '€ 347,08'
echo $currency->toCurrency(null, array('currency' => 'USD')).'<br></br>'; //prints 'US$ 347,08'

As can be seen in above example code, the original currency of $currency (USD) is ignored as the euro-sign is printed while the exchange rate is applied on the value. This is incorrect, if it prints euro then it should be the value 250. The expected result is be the original currency (USD) for $currency.

The second echo is the currency+value that is expected (US$ 347,08), but this is only to show the expected result for this example.

What is clear is that the behavior of Zend_Currency is incorrect in this scenario. Maybe the locale is the problem here but I am not sure.

It is important to have control on the currency and locale seperately as most real case scenario's will not change the currency while locale does (e.g. English translations of the website).

Comments

Posted by Micha Verboeket (mverboeket) on 2010-10-11T10:37:00.000+0000

I found some sort of workaround by changing the first codeline:

<pre class="highlight">
$currency = new Zend_Currency(
    array(
        'value'    => 0.0,
        'currency' => 'USD',
    )
);
...

to this:

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

But it still is unexpected behavior. My initial code example used the example from the manual on http://framework.zend.com/manual/en/… (version 1.10 manual) so I assume this would be the correct way to use it.

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