0
Smart swifty solution, an extension of UITextField
extension UITextField { var floatValue : Float { let numberFormatter = NumberFormatter() numberFormatter.numberStyle = .decimal let nsNumber = numberFormatter.number(from: text!) return nsNumber == nil ? 0.0 : nsNumber!.floatValue } }
And use String(format rather than .description
ResultForSquare.text = String(format: "%.2f", LengthForSquare.floatValue * WidthForSquare.floatValue)
If the locale matters use also NumberFormatter to convert Float to String
Note: Please conform to the naming convention that variable names start with a lowercase letter.