swift - binary operator * cannot be applied to operands of type Int and Double -


i'm trying build simple swift app calculate vat (value added taxes = 20%).

class viewcontroller: uiviewcontroller {  @iboutlet var resulttextview: uitextview! @iboutlet var inputtextfield: uitextfield! @iboutlet var calculatevatbutton: uibutton!  override func viewdidload() {       super.viewdidload()       func taxesfree(number: int)-> double{       var textfield = self.inputtextfield.text.toint()!     let vat = 0.2     var result = textfield * vat      return result                } 

for reason keep getting

binary operator * cannot applied operands of type int , double

on result line

var result = textfield * vat 

inside function.

you should convert 1 type other 1 both variable should same types:

var result: double = double(textfield) * vat 

Comments

Popular posts from this blog

Java 3D LWJGL collision -

spring - SubProtocolWebSocketHandler - No handlers -

methods - python can't use function in submodule -