Could not find an overload for '*' that accepts the supplied argument

前端 未结 1 1749
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-10 06:14

I have converted a String to an Int by by using toInt(). I then tried multiplying it by 0.01, but I get an error that says Could

相关标签:
1条回答
  • 2020-12-10 06:18

    Swift seems to be fairly picky about implied type casting, so in your example you're multiplying str (an Integer) by 0.01 (a Double) so to resolve the error, you'll need to cast it like this:

    var str: Int = 0
    var pennyCount = 0.00
    str = pennyTextField.text.toInt()!
    pennyCount = Double(str) * 0.01
    
    0 讨论(0)
提交回复
热议问题