BMI = [weight(kg)]/ [height(m)] (*Formula given)
import UIKit
class BMIViewController: UIViewController {
@IBOutlet weak var txtHeight: UITextField!
@IBOutlet weak var txtWeight: UITextField!
@IBOutlet weak var lblOutput: UILabel!
@IBAction func btnCalculateBMI(_ sender: Any) {
let height = Double(txtHeight.text!)
let weight = Double(txtWeight.text!)
let bmi = weight! / (height! * height!)
lblOutput.text = String(bmi)
}
}
When running the application, there was too much decimals. How am I able to fix this issue?enter image description here