Swift iOS 8浮动到textField

时间:2014-09-10 03:48:01

标签: swift textfield ios8

如何在swift中将Float放入textField,这是我用Int做的方式

oneValue,twoValue,threeValue是textFields

   @IBAction func calculateButton(sender: UIButton) {
    var value1 = oneValue.text .toInt()
    value1 = value1! * 5
    var value2 = twoValue.text .toInt()
    value2 = value2! * 3
    var value3 = threeValue.text .toInt()
    value3 = value3! * 8


    totalTextField.text = " $ \(value1! + value2! + value3!)"

1 个答案:

答案 0 :(得分:0)

类型之间的语法没有区别。如果您想知道如何格式化浮点数,那么SO上至少有两个好帖子。简而言之,在操场上:

let one:Float = 1.0, two:Float = 2.0, three:Float = 3.0
let s = "\(one + two + three)"
s // 6.0