Question: Swift. Trying to convert decimal to fraction. Can NumberFormatter (https://developer.apple.com/documentation/foundation/numberformatter) help me convert decimal to fraction? If so can you help me convert with my

Swift. Trying to convert decimal to fraction. Can NumberFormatter (https://developer.apple.com/documentation/foundation/numberformatter) help me convert decimal to fraction? If so can you help me convert with my sample code? If not what are my other options?

var maximumFractionDigits: Int { get set }

===============code==============================

import UIKit

class ViewController: UIViewController {

@IBOutlet weak var textF: UITextField!

@IBOutlet weak var answer: UILabel!

override func viewDidLoad() {

super.viewDidLoad()

// Do any additional setup after loading the view, typically from a nib.

}

@IBAction func enter(_ sender: Any) {

Double(textF.text!) == nil

var guessNumber = Double(textF.text!);

var maximumFractionDigits = guessNumber //not declare correctly open to sugguestion

answer.text = "\(guessNumber!) "

}

override func didReceiveMemoryWarning() {

super.didReceiveMemoryWarning()

// Dispose of any resources that can be recreated.

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!