我正在尝试构建一个简单的 Swift 应用来计算增值税(增值税 = 20%)。
func taxesFree(number: Int) -> Double {
var textfield = self.inputTextField.text.toInt()!
let VAT = 0.2
var result = textfield * VAT
return result
}
出于某种原因,我不断得到
Binary operator * cannot be applied to operands of type Int and Double
在线
var result = textfield * VAT
最佳答案
你应该将一种类型转换为另一种类型,这样两个变量应该是相同的类型:
var result: Double = Double(textfield) * VAT
关于swift - 二元运算符 * 不能应用于 Int 和 Double 类型的操作数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30528748/