Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/drupal/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Zend framework zend货币负号_Zend Framework_Zend View - Fatal编程技术网

Zend framework zend货币负号

Zend framework zend货币负号,zend-framework,zend-view,Zend Framework,Zend View,你好,我正在使用Zend_货币 在某个view.phtml文件中 echo $this->currency($gimme_my_money); 这就是我得到的 € 19.373,25 -€ 116,07 我怎样才能让它像这样打印负数 € -116,07 试试这个: class My_View_Helper_Currency extends Zend_View_Helper_Abstract { /** * Format a numeric currency valu

你好,我正在使用Zend_货币

在某个view.phtml文件中

echo $this->currency($gimme_my_money);
这就是我得到的

€ 19.373,25
-€ 116,07
我怎样才能让它像这样打印负数

€ -116,07
试试这个:

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();
    }
}
试试这个:

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();
    }
}

我认为Zend_货币中没有内置此格式选项

您可以做的是将货币符号移到右侧:

$this->view->total = new Zend_Currency(array('value' => $total, 'position' => Zend_Currency::RIGHT));
然后,您的货币将在右侧显示货币符号:

 -19.373,25 €

如果您想要自定义格式,在符号€-116,07后加上负号,则必须编写自己的货币格式设置程序或在Zend_currency上构建。我认为Zend_currency中没有内置此格式设置选项

您可以做的是将货币符号移到右侧:

$this->view->total = new Zend_Currency(array('value' => $total, 'position' => Zend_Currency::RIGHT));
然后,您的货币将在右侧显示货币符号:

 -19.373,25 €

如果您想要自定义格式,在符号€-116,07后加上负号,则必须编写自己的货币格式设置程序或在Zend_currency上构建,只需覆盖格式选项,如下所示:

$cur = new Zend_Currency(array('format' => '¤ #,##0.00;¤ -#,##0.00'));
诀窍是在字符串的第二部分,逗号之后,我检查了它的意大利语区域设置,这里提供的格式字符串是·,0.00


这是用ZF 1.11.7测试的,只需覆盖如下格式选项:

$cur = new Zend_Currency(array('format' => '¤ #,##0.00;¤ -#,##0.00'));
诀窍是在字符串的第二部分,逗号之后,我检查了它的意大利语区域设置,这里提供的格式字符串是·,0.00

这是用ZF 1.11.7测试的