im trying to get a button to output numbers onto a textfield but i keep getting this error
this is my code, the amountOutput is the one with the error
@IBAction func Output(sender: AnyObject) {
yieldOutput.text = String (format:"%.2f", yield[1] )
amountOutput.text = Double (typeAmount * (yieldOutput / 100)) + unit
}
yieldOutput
in your code isn't a number, it's a text field. That means that to use the value in it, you need to transform it into a number or use a variable that already holds that value. In your case, yield[1]
is the variable you use to set the value for yieldOutput
. Just do:
amountOutput.text = Double (typeAmount * (yield[1] / 100)) + unit
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.