PhpRiot
Become Zend Certified

Prepare for the ZCE exam using our quizzes (web or iPad/iPhone). More info...


When you're ready get 7.5% off your exam voucher using voucher CJQNOV23 at the Zend Store

Where is the currency?

The position where the currency sign or name will be displayed depends on the locale. Still, when you want to define this setting yourself you have to use the display option and provide one of the following constants:

Table 45. Available positions for the currency

Constant Description
STANDARD Sets the standard position as defined within the locale
RIGHT Displays the currency representation at the right side of the value
LEFT Displays the currency representation at the left side of the value

Example 161. Setting the currency position

Let's assume that your client has again set "en_US" as locale. Using no option the returned value could look like this:

<?php
$currency 
= new Zend_Currency(
    array(
        
'value' => 100,
    )
);

print 
$currency// Could return '$ 100'

So by using the default setting the currency (in our case $) could either be rendered left or right from the value. Now let's define a fixed position:

<?php
$currency 
= new Zend_Currency(
    array(
        
'value'    => 100,
        
'position' => Zend_Currency::RIGHT,
    )
);

print 
$currency// Could return '100 $';

Note that in the second snippet the position of USD is fixed regardless of the used locale or currency.


Zend Framework