不是' /'候选人产生预期的情境结果类型' NSNumber'

时间:2016-09-15 18:14:26

标签: swift3

我刚刚更新到swift 3并得到了这个问题。

issue

let percentString = NumberFormatter.localizedString(
        from: Double(correctGuesses) / Double(totalGuesses),
        number: NumberFormatter.Style.percent)

2 个答案:

答案 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)