I am having a problem using NumberFormatter
. I would like for the variable output
to only contain a certain amount of digits.
E.g. 3.14 instead of 3.14567899
I am am getting an error Ambiguous reference to member 'string(from:)'
:
func calculateLength() {
let formatter = NumberFormatter()
formatter.numberStyle = .decimal
formatter.minimumFractionDigits = 2
formatter.maximumFractionDigits = 2
print(startingLength)
print(endingLength)
if startingLength == "Feet" && endingLength == "Inches" {
output = formatter.string(from: NSNumber(value: Double(lengthTextFieldValue) * 12) // This is where I am getting the error
print(output)
lengthOutputLabel.text = ("\(lengthTextFieldValue) ft = \(output) inches")
}
}
What is the proper way?