Where is the currency?

How does the currency look like?

How the value of a currency will be rendered depends mainly on the used locale. There are several informations which are set by the locale. Each of them can manually be overridden by using the proper option.

For example, most locales are using the Latin script for rendering numbers. But there are languages like "Arabic" which are using other digits. And when you have an Arabic website you may also want to render other currencies by using the Arabic script. See the following example:

Example #1 Using a custom script

Let's expect that we are again using our "Dollar" currency. But now we want to render our currency by using the Arabic script.

  1. $currency = new Zend_Currency(
  2.     array(
  3.         'value'  => 1000,
  4.         'script' => 'Arab',
  5.     )
  6. );
  7.  
  8. print $currency; // Could return '$ ١٬٠٠٠٫٠٠'

For more informations about available scripts look into Zend_Locale's chapter about numbering systems.

But also the formatting of a currency number (money value) can be changed. Per default it depends on the used locale. It includes the separator which will be used between thousands, which sign will be used as decimal point, and also the used precision.

  1. $currency = new Zend_Currency(
  2.     array(
  3.         'value'    => 1000,
  4.         'currency' => 'USD'
  5.         'format'   => 'de',
  6.     )
  7. );
  8.  
  9. print $currency; // Could return '$ 1.000'

There are two ways to define the format which will be used. You can either give a locale or define a format manually.

When you are using a locale for defining the format all is done automatically. The locale 'de', for example, defines '.' as separator for thousands and ',' as decimal point. Within English this is reversed.

  1. $currency_1 = new Zend_Currency(
  2.     array(
  3.         'value'    => 1000,
  4.         'currency' => 'USD'
  5.         'format'   => 'de',
  6.     )
  7. );
  8.  
  9. $currency_2 = new Zend_Currency(
  10.     array(
  11.         'value'    => 1000,
  12.         'currency' => 'USD'
  13.         'format'   => 'en',
  14.     )
  15. );
  16.  
  17. print $currency_1; // Could return '$ 1.000'
  18. print $currency_2; // Could return '$ 1,000'

When you define it manually then you must conform the format as described in this chapter about localizing. See the following:

  1. $currency = new Zend_Currency(
  2.     array(
  3.         'value'    => 1000,
  4.         'currency' => 'USD'
  5.         'format'   => '#0',
  6.     )
  7. );
  8.  
  9. print $currency; // Could return '$ 1000'

In the above snippet we deleted the separator and also the precision.


Where is the currency?