Swift - How to multiply value from UITextField

不想你离开。 提交于 2019-12-06 05:13:35

It should work with .toInt():

if let number = self.textFieldField.text?.toInt() {
  self.labelLabel.text = "\(number * conversionRate)"
}

You can try this

    var conversionRate = 7;
    var value = self.nameLbl.text.toInt();
    value = value!*conversionRate;
    self.nameLbl.text = NSString(format:"%d",value!)as String;

OR

    var conversionRate = 7;
    var value : Int = self.nameLbl.text.toInt()!;
    value = value*conversionRate;
    self.nameLbl.text = String(value);

OR

    var conversionRate = 7;
    if let number = nameLbl.text?.toInt() {
        self.nameLbl.text = "\(number * conversionRate)"
    }
    let a = textFieldField.text
    let conversionRate = 7
    let b = Int(a!)! * conversionRate //use Double(a!)! instead of Int(a!)! if your are using a floating point value for "conversionRate" variable.
    labelLabel.text = ("\(b)")

Happy coding!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!