Im a total newbie to Swift and pretty poor in English. However, I'm trying to build a priceless we use in our company.
I want the user to type in some figures, and let them know the price. It contains a lot of variables but i think everyone is configured the same.
Lets say i want the user to type in an amount in at UiTextField, and a label shall display 1000 / amount with two decimals.
My code at this point is this;
import UIKit
import Foundation
class ViewController: UIViewController {
@IBOutlet weak var svar: UILabel!
@IBOutlet weak var inpu2: UITextField!
override func viewDidLoad() {
super.viewDidLoad()
svar.text = ""
}
@IBAction func input(_ sender: Any) {
if let treStørrelse = Float(inpu2.text!) {
svar.text = "\(1000 / treStørrelse)"
}
}
}
My output at this point is shown as xx.xxxxxxxxxx I want it to be shown xx.xx
I also need to use the answer in further calculation.