2011-12-05 200 views
1

你好,我是用Zend_Currency的Zend公司货币负号

class Currency extends Zend_View_Helper_Abstract 
{ 

    public function currency($number, $locale = 'it_IT') { 
     $currency = new Zend_Currency($locale); 

     $number = $number + 0.00;//convert to float 

     return $currency->toCurrency((float) $number); 

    } 
} 

在一些人认为一个.phtml文件

echo $this->currency($gimme_my_money); 

,这就是我得到

€ 19.373,25 
-€ 116,07 

怎么能我得到它打印负数如

€ -116,07 

回答

1

我不认为这格式化选项,内置Zend_Currency的。

你可以做什么,是货币符号移动到右侧:

$this->view->total = new Zend_Currency(array('value' => $total, 'position' => Zend_Currency::RIGHT)); 

然后你的货币将与右边的货币符号显示:

-19.373,25 € 

如果您想要自定义格式,在符号后面带负号(€ -116,07),则必须编写自己的货币格式化程序或建立在Zend_Currency之上

0

试试这个:

class My_View_Helper_Currency extends Zend_View_Helper_Abstract 
{ 
    /** 
    * Format a numeric currency value and return it as a string 
    * 
    * @param int|float $value any value that return true with is_numeric 
    * @param array  $options additional options to pass to the currency 
    *       constructor 
    * @param string $locale locale value 
    * 
    * @throws InvalidParameterException if the $value parameter is not numeric 
    * @return string the formatted value 
    */ 
    public function currency($value, $options = array(), $locale = null) 
    { 
     if (!is_numeric($value)) { 
      throw new InvalidArgumentException(
       'Numeric argument expected ' . gettype($value) . ' given' 
      ); 
     } 
     $options = array_merge($options, array('value' => $value)); 
     $currency = new Zend_Currency($options, $locale); 
     return $currency->toString(); 
    } 
} 
5

只是简单地覆盖的格式选项是这样的:

$cur = new Zend_Currency(array('format' => '¤ #,##0.00;¤ -#,##0.00')); 

的诀窍是在串的第二部分(逗号之后),我检查了它的意大利语言环境和格式字符串提供有¤# ,## 0.00。

这是测试与ZF 1.11.7