I am trying to convert the value of a text field, which the user enters. As users are able to enter decimal values in european number format too, I use numberformatter for that. This was what I was trying:
let newprice = MaximumPriceLabel.text as! String
print(newprice) -> result: Optional("10,00")
print(formatter.number(from: newprice as String)) -> result: nil
print(Double(formatter.number(from: ("10,11"))!)) -> result: 10.11 -> that is what I want
So there is a value stored in the variable newprice, but when formatting, it returns nil. When I test it with a manual value, it works. Is there anything I am doing wrong? Formatter.local is set to Locale.current.
Update: The problem seems to be that the MaximumPriceLabel.text contains not only the value I need, but really the text "Optional("10,00") - which fails when converting to a number. The value is filled like this:
self.MaximumPriceLabel.text = String(describing: formatter.string(from: NSNumber(value: desprice)))
and when I do a print afterwards, I receive "Optional("Optional(\"10,00\")")" -> even when I clear the variable MaximumPriceLabel.text first.