Zend_Currency bug??

View: New views
3 Messages — Rating Filter:   Alert me  

Zend_Currency bug??

by Nogyara :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi ZFers,
I found something strange when tried to use Zend_Currency. It seems that 'currency' option does not work. In my understanding of manual, these both examples should print amount in EUR:

//prints amount in GBP
$oCurrency = new Zend_Currency('en_GB');
var_dump($oCurrency->toCurrency(1000, array('currency' => 'EUR', 'precision' => 1)));

//prints amount in USD
$oCurrency = new Zend_Currency('USD', 'en_GB');
var_dump($oCurrency->toCurrency(1000, array('currency' => 'EUR', 'precision' => 1)));

Options are not ignored, 'precision' option is applied as should be, however, setting of 'currency' option seems to have no effect. Is it bug in Zend_Currency?
[tried it on both ZF 1.03 and 1.04]

P.S.: BTW, congratulations to all I18N team for great work on Zend_Locale & the rest. As what I tried so far, very powerful and easy to use and with caching support, not slow at all. Really perfect work!

Re: Zend_Currency bug??

by thomasW :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Nogyara wrote:
I found something strange when tried to use Zend_Currency. It seems that 'currency' option does not work. In my understanding of manual, these both examples should print amount in EUR:

//prints amount in GBP
$oCurrency = new Zend_Currency('en_GB');
var_dump($oCurrency->toCurrency(1000, array('currency' => 'EUR', 'precision' => 1)));

//prints amount in USD
$oCurrency = new Zend_Currency('USD', 'en_GB');
var_dump($oCurrency->toCurrency(1000, array('currency' => 'EUR', 'precision' => 1)));

Options are not ignored, 'precision' option is applied as should be, however, setting of 'currency' option seems to have no effect. Is it bug in Zend_Currency?
[tried it on both ZF 1.03 and 1.04]

P.S.: BTW, congratulations to all I18N team for great work on Zend_Locale & the rest. As what I tried so far, very powerful and easy to use and with caching support, not slow at all. Really perfect work!
Thank you...

Related to your problem:
You set the currency name to be a defined value, but you did not set it do be displayed.
As from your initiation a currency sign is available it will be used instead.

You could eighter use the option 'symbol' => 'EUR' or simply use 'EUR' at initialisation.

Greetings
Thomas
I18N Team Leader

Re: Zend_Currency bug??

by Nogyara :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Thanks, Thomas, but this is not exactly what I tried to achieve. Sorry, I didn't describe the problem too much clearly. I didn't want to display:
"1000 EUR"
but rather
"1000 €"
(I mean, symbol for EURO, not its 3-letter code). So, depending on options passed to option array, I would like print:
"1000 €", "1000 $", "1000 £", etc.

With the 'symbol' option you adviced, manual and couple of tries, I found out the solution:
$oCurrency = new Zend_Currency('en_GB');
var_dump($oCurrency->toCurrency(1000, array('symbol' => $oCurrency->getSymbol('EUR', 'en_GB'), 'precision' => 1)));
var_dump($oCurrency->toCurrency(1000, array('symbol' => $oCurrency->getSymbol('USD', 'en_GB'), 'precision' => 1)));
(locale must be set in getSymbol() otherwise Exception is thrown)

Thanks for your help
Best regards

thomasW wrote:
You set the currency name to be a defined value, but you did not set it do be displayed.
As from your initiation a currency sign is available it will be used instead.

You could eighter use the option 'symbol' => 'EUR' or simply use 'EUR' at initialisation.