问题描述:

I'm trying to get my UItextField to accept floating point but at the moment, it will only accept an integer. How can I get it to accept floating point in Swift?

class ViewController: UIViewController, UITextFieldDelegate {

@IBOutlet weak var Swallow13Button: UIButton!

@IBAction func Swallow13Button (sender: AnyObject) {

let a:Int? = data1.text.toInt()

if a > 13.13 {

self.DimensionLabel.text = "Fail Send DWG For Review"

self.view.endEditing(true)

}

else {

self.DimensionLabel.text = "Pass Send DWG for Review"

self.view.endEditing(true)

}

}

网友答案:

You can convert using NSString's floatValue:

let a: Float = (data1.text as NSString).floatValue
网友答案:

You can convert to float like this

let a = (data1 as NSString).floatValue
相关阅读:
Top