I have a dictionary with Bill Price as Optional Any My issue is that I want to convert it in Currency with the function below:
let currencyFormatter = NumberFormatter()
currencyFormatter.usesGroupingSeparator = true
currencyFormatter.numberStyle = .currency
currencyFormatter.locale = Locale.current
let priceString = currencyFormatter.string(from: ToConvert2)
print(priceString) // Displays $9,999.99 in the US locale
Im using the following data:
dicType.value(forKey: "BON_PRIX")
--> Optional - some : 103.28
I tried:
let ToConvert = (String(describing: dicType.value(forKey: "BON_PRIX") as! String))
let ToConvert2 = NSNumber(value: Int(ToConvert)!)
but I'm getting Fatal error,
Unexpectedly found nil while unwrapping an Optional value
I tried few things but didn't find the right way. So the point is to convert data from an external server into EUR with roundup with 2 decimals.
Thanks in advance for your help!