Zend Framework – Zend Currency

Today I got myself up with searching on Google and trying to understand the Zend Currency (a great way to easily format numbers in currencies format – PHP does have a function but it does not work under Windows) examples in the Zend Framework documentation. Whatever I did it was not working until I have bumped into a help manual from Zend that showed a better example.

Basically, the Zend Currency will totally bypass the parameters in the array and throw an error if the like the examples on the API documentation are set:

$currency = new Zend_Currency(
‘value’   => 100,
‘display’ => Zend_Currency::USE_SHORTNAME,
print $currency; // Could return ‘USD 100’
In order for this to work you need to first create the Zend_Currency object passing the locale and currency format (or if you don’t pass any parameter, it will just grab the format and locale from the system).
$currency = new Zend_Currency();
echo $currency->toCurrency(100); // could return USD 100
If you need to pass the locale or currency format this is how you can do:
$currency = new Zend_Currency(‘en_US’, ‘EUR’); // set locale to USA and the currency format to Euro
echo $currency->toCurrency(100);
If we do this same example following the API documentation we would:
$currency = new Zend_Currency(array(‘locale’ => ‘en_US’, ‘value’ => 100, ‘currency’ => ‘EUR’);
echo $currency; // doesn’t work unless you set the locale using the Zend_Registry and Zend_Locale
Anyway is worth to log this kind of troubleshoot.
Have fun.

About mcloide

Making things simpler, just check: http://www.mcloide.com View all posts by mcloide

3 responses to “Zend Framework – Zend Currency

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: