This is what I do now:
extension Decimal { var formattedAmount: String { let formatter = NumberFormatter() formatter.generatesDecimalNumbers =
This:
formatter.string(from: ...) // requires a NSNumber
You can either do this:
formatter.string(for: self) // which takes Any as argument
Or:
string(from: self as NSDecimalNumber) // cast self to NSDecimalNumber
This should work
extension Decimal {
var formattedAmount: String? {
let formatter = NumberFormatter()
formatter.generatesDecimalNumbers = true
formatter.minimumFractionDigits = 2
formatter.maximumFractionDigits = 2
return formatter.string(from: self as NSDecimalNumber)
}
}