2
0

Zend_Currency-Number.xml 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!-- Reviewed: no -->
  3. <sect1 id="zend.currency.number">
  4. <title>How does the currency look like?</title>
  5. <para>
  6. How the value of a currency will be rendered depends mainly on the used locale. There
  7. are several informations which are set by the locale. Each of them can manually be
  8. overridden by using the proper option.
  9. </para>
  10. <para>
  11. For example, most locales are using the Latin script for rendering numbers. But there
  12. are languages like "Arabic" which are using other digits. And when you have an Arabic
  13. website you may also want to render other currencies by using the Arabic script. See
  14. the following example:
  15. </para>
  16. <example id="zend.currency.number.example-1">
  17. <title>Using a custom script</title>
  18. <para>
  19. Let's expect that we are again using our "Dollar" currency. But now we want to
  20. render our currency by using the Arabic script.
  21. </para>
  22. <programlisting language="php"><![CDATA[
  23. $currency = new Zend_Currency(
  24. array(
  25. 'value' => 1000,
  26. 'script' => 'Arab',
  27. )
  28. );
  29. print $currency; // Could return '$ ١٬٠٠٠٫٠٠'
  30. ]]></programlisting>
  31. </example>
  32. <para>
  33. For more informations about available scripts look into
  34. <classname>Zend_Locale</classname>'s <link linkend="zend.locale.numbersystems">chapter
  35. about numbering systems</link>.
  36. </para>
  37. <para>
  38. But also the formatting of a currency number (money value) can be changed. Per default
  39. it depends on the used locale. It includes the separator which will be used between
  40. thousands, which sign will be used as decimal point, and also the used precision.
  41. </para>
  42. <programlisting language="php"><![CDATA[
  43. $currency = new Zend_Currency(
  44. array(
  45. 'value' => 1000,
  46. 'currency' => 'USD'
  47. 'format' => 'de',
  48. )
  49. );
  50. print $currency; // Could return '$ 1.000'
  51. ]]></programlisting>
  52. <para>
  53. There are two ways to define the format which will be used. You can either give a
  54. locale or define a format manually.
  55. </para>
  56. <para>
  57. When you are using a locale for defining the format all is done automatically. The
  58. locale 'de', for example, defines '.' as separator for thousands and ',' as decimal
  59. point. Within English this is reversed.
  60. </para>
  61. <programlisting language="php"><![CDATA[
  62. $currency_1 = new Zend_Currency(
  63. array(
  64. 'value' => 1000,
  65. 'currency' => 'USD'
  66. 'format' => 'de',
  67. )
  68. );
  69. $currency_2 = new Zend_Currency(
  70. array(
  71. 'value' => 1000,
  72. 'currency' => 'USD'
  73. 'format' => 'en',
  74. )
  75. );
  76. print $currency_1; // Could return '$ 1.000'
  77. print $currency_2; // Could return '$ 1,000'
  78. ]]></programlisting>
  79. <para>
  80. When you define it manually then you must conform the format as described in
  81. <link linkend="zend.locale.number.localize.table-1">this chapter about
  82. localizing</link>. See the following:
  83. </para>
  84. <programlisting language="php"><![CDATA[
  85. $currency = new Zend_Currency(
  86. array(
  87. 'value' => 1000,
  88. 'currency' => 'USD'
  89. 'format' => '#0',
  90. )
  91. );
  92. print $currency; // Could return '$ 1000'
  93. ]]></programlisting>
  94. <para>
  95. In the above snippet we deleted the separator and also the precision.
  96. </para>
  97. </sect1>