1 <?xml version="1.0" encoding="UTF-8"?>
3 <sect1 id="zend.currency.value">
4 <title>How much is my currency?</title>
7 When you are working with currencies then you normally want to display an amount of
8 money. And when you work with different currencies then you have to do this with three
9 different things. The amount you want to display, the precision you want to use, and
10 probably the exchange rate.
13 <sect2 id="zend.currency.value.money">
14 <title>Working with currency values</title>
17 The currency value, a.k.a. the money, you want to use can easily be set by using the
18 <property>value</property> option.
21 <programlisting language="php"><![CDATA[
22 $currency = new Zend_Currency(
29 print $currency; // Could return '$ 1.000'
33 Using the <methodname>setFormat()</methodname> method with this array option, and
34 also by using the <methodname>setValue()</methodname> method you can set the value
38 <programlisting language="php"><![CDATA[
39 $currency = new Zend_Currency(
46 print $currency->setValue(2000); // Could return '$ 2.000'
50 With the <methodname>getValue()</methodname> method you will get the actual set
55 <sect2 id="zend.currency.value.precision">
56 <title>Using precision on currencies</title>
59 When working with currencies they you probably also have to handle precision.
60 Most currencies use a precision of 2. This means that when you have 100 US dollars
61 you could also have 50 cents. The related value is simply a floating value.
64 <programlisting language="php"><![CDATA[
65 $currency = new Zend_Currency(
72 print $currency; // Could return '$ 1.000,50'
76 Of course, as the default precision is 2, you will get '00' for the decimal value
77 when there is no precision to display.
80 <programlisting language="php"><![CDATA[
81 $currency = new Zend_Currency(
88 print $currency; // Could return '$ 1.000,00'
92 To get rid of this default precision you could simply use the
93 <property>precision</property> option and set it to '0'. And you can set any other
94 precision you want to use between 0 and 9. All values will be rounded or streched
95 when they don't fit the set precision.
98 <programlisting language="php"><![CDATA[
99 $currency = new Zend_Currency(
107 print $currency; // Could return '$ 1.000'