无法让 UItextfield 接受 Swift 中的浮点数
Can't get UItextfield to accept floating point in Swift
我正在尝试让我的 UItextField 接受浮点数,但目前它只接受整数。我怎样才能让它接受 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)
}
}
你可以像这样转换为浮点数
let a = (data1 as NSString).floatValue
您可以使用 NSString
的 floatValue
:
进行转换
let a: Float = (data1.text as NSString).floatValue
我正在尝试让我的 UItextField 接受浮点数,但目前它只接受整数。我怎样才能让它接受 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)
}
}
你可以像这样转换为浮点数
let a = (data1 as NSString).floatValue
您可以使用 NSString
的 floatValue
:
let a: Float = (data1.text as NSString).floatValue