我刚刚更新到swift 3并得到了这个问题。
let percentString = NumberFormatter.localizedString(
from: Double(correctGuesses) / Double(totalGuesses),
number: NumberFormatter.Style.percent)
答案 0 :(得分:2)
var correctGuesses = 10
var totalGuesses = 20
var result = NSNumber(value: correctGuesses / totalGuesses)
let percentString = NumberFormatter.localizedString(
from: result,
number: NumberFormatter.Style.percent
)
答案 1 :(得分:-1)
或者简单地说,不添加另一个var
let percentString = NumberFormatter.localizedString(
from: NSNumber(value: Double(correctGuesses) / Double(totalGuesses)),
number: NumberFormatter.Style.percent)