PHP NumberFormatter setPattern货币符号

时间:2016-06-16 18:37:18

标签: php numberformatter

我为我的号码格式设置了func menuWillOpen(menu: NSMenu) { drawHighlight(true) } func menuDidClose(menu: NSMenu) { drawHighlight(false) } func drawHighlight(highlight:Bool) { let image = NSImage(size: self.frame.size) image.lockFocus() statusItem.drawStatusBarBackgroundInRect(self.bounds, withHighlight: highlight) image.unlockFocus() self.layer?.contents = image } 的语言环境。将货币格式设置为en会产生USD,而将货币格式化为$x.xx会产生CAD。我已经尝试将模式设置为CA$x.xx¤#,##0.00,但第一个并不是一直在货币符号之前添加字母而第二个不按我希望的那样执行。在格式化货币时,有人可以建议如何同时获得¤¤#,##0.00US$x.xx吗?

1 个答案:

答案 0 :(得分:0)

您可以执行类似

的操作
if(objNumberFormatter->getTextAttribute(NumberFormatter::CURRENCY_CODE) == 'USD')
    $objNumberFormatter->setAttribute(NumberFormatter::PAD_BEFORE_PREFIX, 'US');

OR

if($currency == 'USD')
    $objNumberFormatter->setAttribute(NumberFormatter::PAD_BEFORE_PREFIX, 'US');

或者你可以改变它的模式

if($currency == 'USD')
     $objNumberFormatter->setPattern('US ¤#,##0.00');