当前位置: 动力学知识库 > 问答 > 编程问答 >

xcode - Can't get UItextfield to accept floating point in Swift

问题描述:

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
分享给朋友:
您可能感兴趣的文章:
随机阅读: