【问题标题】:Swift NSNumberFormatter CurrencyStyle Without Symbol没有符号的 Swift NSNumberFormatter CurrencyStyle
【发布时间】:2015-05-31 19:22:32
【问题描述】:

这个问题已经在objective-c here 中得到解答。我怎样才能在 Swift 中做到这一点?

【问题讨论】:

  • 你如何在这里发布你的实际问题?
  • 我怎样才能接受它们作为答案?其中一些非常好
  • 对于您自己的问题,您只能接受一个正确答案。对于其他问题,您只能使用答案旁边的箭头为有用的答案投票。
  • 在页面上看不到任何接受按钮。我应该点击答案,然后它会出现吗?

标签: swift currency nsnumberformatter


【解决方案1】:
import UIKit

let nf = NumberFormatter()
nf.currencySymbol = ""
nf.numberStyle = .currency
let stringForNumber = nf.string(for: 100)  // "100.00"

【讨论】:

  • nf.currencySymbol = "" 得到预期的声明。
  • 它已经被导入了。投票需要我 15 点声望。
  • 如果是iOS你必须导入UIKit。上面的代码应该没问题
  • xcode 版本 6.3.1 (6D1002) 中弹出错误信息。 @Leo Dabus
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-04-13
  • 1970-01-01
  • 1970-01-01
  • 2023-03-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多