ZEND currency symbol is displaying 1

2019-02-21 04:00发布

I'm using zend currency to display the currency based on locale. When I use the following code the symbol gets replaced by 1 instead of simply being removed:

$currency = new Zend_Currency($locale); $currency->setFormat(array('symbol' => Zend_Currency::NO_SYMBOL));

What normally gets returned is this: € 2.500,01 but after the "setFormat" call I'm getting this: 1 2.500,01

I don't want the "1 " in there.

Any ideas on how to fix this?

Thanks.

2条回答
爷、活的狠高调
2楼-- · 2019-02-21 04:45

Here's the ZF tutorial page for this. It looks like it will set a person in the right direction: zend currency tutorial page

查看更多
ら.Afraid
3楼-- · 2019-02-21 04:59

You're setting the wrong option in setFormat. You need to set display to Zend_Currency::NO_SYMBOL. Like this:

$c = new Zend_Currency();
$c->setFormat(array('display' => Zend_Currency::NO_SYMBOL));
echo $c->toCurrency(2500.01);

Which outputs

2,500.01

The way you are currently doing it is literally setting the symbol to 1 because that's what the constant NO_SYMBOL evaluates to.

查看更多
登录 后发表回答