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);
使用 Zend_currency ,这就是我得到的
€ 19.373,25
-€ 116,07
,如何让它打印负数,例如
€ -116,07
Hello i am using Zend_currency
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);
}
}
in a some view .phtml file
echo $this->currency($gimme_my_money);
and this is what i get
€ 19.373,25
-€ 116,07
how can i get it to print negative numbers like
€ -116,07
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
只需像这样覆盖格式选项:
技巧在于字符串的第二部分(逗号之后),我检查了它的意大利语语言环境,并且提供的格式字符串是 ¤ #,##0.00。
这是用 ZF 1.11.7 测试的
Just overwrite the format option like this:
The trick is in the second part of the string (after the comma), I've checked it for Italian locale and the format string provided there is ¤ #,##0.00.
This is tested with ZF 1.11.7
我不认为这个格式化选项内置于 Zend_Currency 中。
您可以做的是将货币符号移至右侧:
然后您的货币将显示在右侧,货币符号如下:
如果您想要自定义格式,则在符号后面带有负号,(
€ -116,07
),您必须编写自己的货币格式化程序或构建在Zend_Currency
之上I don't think this formatting option is built into Zend_Currency.
What you can do, is move the currency symbol to the right side:
And then your currencies will be displayed with the currency symbol on the right:
If you want a custom formatting, with the negative sign after the symbol, (
€ -116,07
), you will have to write your own currency formatter or built on top ofZend_Currency
试试这个:
try this: